{"id":2619,"date":"2023-07-21T11:47:01","date_gmt":"2023-07-21T11:47:01","guid":{"rendered":"https:\/\/statorials.org\/it\/se-allora-no\/"},"modified":"2023-07-21T11:47:01","modified_gmt":"2023-07-21T11:47:01","slug":"se-allora-no","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/se-allora-no\/","title":{"rendered":"Come utilizzare if-then-do in sas (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare un&#8217;istruzione <strong>IF-THEN-DO<\/strong> in SAS per <em>eseguire<\/em> un blocco di istruzioni <em>se<\/em> una condizione \u00e8 vera.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questa istruzione utilizza la seguente sintassi di base:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #3366ff;\">if<\/span> <span style=\"color: #000000;\">var1 = \" <span style=\"color: #ff0000;\">value<\/span> \"<\/span> <span style=\"color: #3366ff;\">then<\/span> <span style=\"color: #3366ff;\">do<\/span> <span style=\"color: #000000;\">;\n    new_var2 = 10;\n    new_var3 = 5;\n<\/span><span style=\"color: #3366ff;\">end<\/span> <span style=\"color: #000000;\">;\n<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\"><strong>Nota<\/strong> : un&#8217;istruzione IF-THEN viene utilizzata quando si desidera eseguire <em>una singola<\/em> istruzione. Un&#8217;istruzione IF-THEN-DO viene utilizzata quando si desidera eseguire pi\u00f9 istruzioni.<\/span><\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare nella pratica un&#8217;istruzione <strong>IF-THEN-DO<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><b>Esempio: <strong>IF-THEN-DO in SAS<\/strong><\/b><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente set di dati in SAS che mostra le vendite totali effettuate da due negozi in giorni consecutivi:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">\/*create dataset*\/\n<\/span><span style=\"color: #800080;\">data<\/span> original_data;\n    <span style=\"color: #3366ff;\">input<\/span> store $sales;\n    <span style=\"color: #3366ff;\">datalines<\/span> ;\nAt 14\nAt 19\nAt 22\nAt 20\nAt 16\nAt 26\nB40\nB43\nB29\nB 30\nB35\nB 33\n;\n<span style=\"color: #800080;\">run<\/span> ;\n\n<span style=\"color: #008000;\">\/*view dataset*\/\n<\/span><span style=\"color: #800080;\">proc print<\/span> <span style=\"color: #3366ff;\">data<\/span> = original_data;<\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-23097 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lagsas3.jpg\" alt=\"\" width=\"146\" height=\"326\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente istruzione IF-THEN-DO per creare due nuove variabili che assumono determinati valori se lo store \u00e8 uguale ad &#8220;A&#8221; nel set di dati originale:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">\/*create new dataset*\/\n<\/span><span style=\"color: #800080;\">data<\/span> <span style=\"color: #000000;\">new_data;\n<\/span><span style=\"color: #3366ff;\">set<\/span> <span style=\"color: #000000;\">original_data;\n<\/span><span style=\"color: #3366ff;\">if<\/span> <span style=\"color: #000000;\">store = \"<\/span> <span style=\"color: #ff0000;\">A<\/span> <span style=\"color: #000000;\">\"<\/span> <span style=\"color: #3366ff;\">then do<\/span> <span style=\"color: #000000;\">;\n    region=\"<\/span> <span style=\"color: #ff0000;\">East<\/span> <span style=\"color: #000000;\">\";\n    country=\"<\/span> <span style=\"color: #ff0000;\">Canada<\/span> <span style=\"color: #000000;\">\";\n<\/span><span style=\"color: #3366ff;\">end<\/span> <span style=\"color: #000000;\">;\n<\/span><span style=\"color: #800080;\">run<\/span> <span style=\"color: #000000;\">;\n\n<\/span><span style=\"color: #008000;\">\/*view new dataset*\/\n<\/span><span style=\"color: #800080;\">proc print<\/span> <span style=\"color: #3366ff;\">data<\/span> <span style=\"color: #000000;\">=new_data;<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-23104 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ifthendo1.jpg\" alt=\"Istruzione IF-THEN-DO in SAS\" width=\"278\" height=\"344\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Ecco come funzionava questo pezzo di codice:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se il negozio era uguale ad &#8220;A&#8221;, veniva creata una nuova variabile denominata <strong>regione<\/strong> con un valore &#8220;Est&#8221; <em>e<\/em> una nuova variabile denominata <strong>paese<\/strong> con un valore &#8220;Canada&#8221;.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Tieni presente che possiamo anche utilizzare pi\u00f9 istruzioni IF-THEN-DO:<\/span><\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">\/*create new dataset*\/\n<\/span><span style=\"color: #800080;\">data<\/span> <span style=\"color: #000000;\">new_data;\n<\/span><span style=\"color: #3366ff;\">set<\/span> <span style=\"color: #000000;\">original_data;\n\n<\/span><span style=\"color: #3366ff;\">if<\/span> <span style=\"color: #000000;\">store = \"<\/span> <span style=\"color: #ff0000;\">A<\/span> <span style=\"color: #000000;\">\"<\/span> <span style=\"color: #3366ff;\">then do<\/span> <span style=\"color: #000000;\">;\n    region=\" <span style=\"color: #ff0000;\">East<\/span> \";\n    country=\" <span style=\"color: #ff0000;\">Canada<\/span> \";\n<\/span><span style=\"color: #3366ff;\">end<\/span> <span style=\"color: #000000;\">;\n\n    <span style=\"color: #3366ff;\">if<\/span> store = \" <span style=\"color: #ff0000;\">B<\/span> \" <span style=\"color: #3366ff;\">then do<\/span> ;\n    region=\" <span style=\"color: #ff0000;\">West<\/span> \";\n    country=\" <span style=\"color: #ff0000;\">USA<\/span> \";\n    <span style=\"color: #3366ff;\">end<\/span> ; \n<\/span><span style=\"color: #800080;\">run<\/span> <span style=\"color: #000000;\">;\n\n<\/span><span style=\"color: #008000;\">\/*view new dataset*\/\n<\/span><span style=\"color: #800080;\">proc print<\/span> <span style=\"color: #3366ff;\">data<\/span> <span style=\"color: #000000;\">=new_data;<\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-23105 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ifthendo2.jpg\" alt=\"\" width=\"286\" height=\"347\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Ecco come funzionava questo pezzo di codice:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">Se il negozio era uguale ad &#8220;A&#8221;, veniva creata una nuova variabile denominata <strong>regione<\/strong> con un valore &#8220;Est&#8221; e una nuova variabile denominata <strong>paese<\/strong> con un valore &#8220;Canada&#8221;.<\/span><\/li>\n<li> <span style=\"color: #000000;\">Se il negozio era uguale a &#8220;B&#8221;, il valore <strong>della regione<\/strong> era &#8220;Ovest&#8221; e il valore <strong>del paese<\/strong> era &#8220;Stati Uniti&#8221;.<\/span><\/li>\n<\/ul>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in SAS:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/normalizzare-i-dati-nella-camera-di-equilibrio\/\" target=\"_blank\" rel=\"noopener\">Come normalizzare i dati in SAS<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/non-rimuovere-i-duplicati\/\" target=\"_blank\" rel=\"noopener\">Come rimuovere i duplicati in SAS<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/senza-sostituire-i-valori-mancanti-con-zero\/\" target=\"_blank\" rel=\"noopener\">Come sostituire i valori mancanti con zero in SAS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare un&#8217;istruzione IF-THEN-DO in SAS per eseguire un blocco di istruzioni se una condizione \u00e8 vera. Questa istruzione utilizza la seguente sintassi di base: if var1 = &#8221; value &#8221; then do ; new_var2 = 10; new_var3 = 5; end ; Nota : un&#8217;istruzione IF-THEN viene utilizzata quando si desidera eseguire una singola [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come utilizzare IF-THEN-DO in SAS (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare IF-THEN-DO in SAS, con diversi esempi.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/se-allora-no\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare IF-THEN-DO in SAS (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare IF-THEN-DO in SAS, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/se-allora-no\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-21T11:47:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lagsas3.jpg\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/se-allora-no\/\",\"url\":\"https:\/\/statorials.org\/it\/se-allora-no\/\",\"name\":\"Come utilizzare IF-THEN-DO in SAS (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-21T11:47:01+00:00\",\"dateModified\":\"2023-07-21T11:47:01+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare IF-THEN-DO in SAS, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/se-allora-no\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/se-allora-no\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/se-allora-no\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare if-then-do in sas (con esempi)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come utilizzare IF-THEN-DO in SAS (con esempi) - Statorials","description":"Questo tutorial spiega come utilizzare IF-THEN-DO in SAS, con diversi esempi.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/it\/se-allora-no\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare IF-THEN-DO in SAS (con esempi) - Statorials","og_description":"Questo tutorial spiega come utilizzare IF-THEN-DO in SAS, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/se-allora-no\/","og_site_name":"Statorials","article_published_time":"2023-07-21T11:47:01+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lagsas3.jpg"}],"author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/se-allora-no\/","url":"https:\/\/statorials.org\/it\/se-allora-no\/","name":"Come utilizzare IF-THEN-DO in SAS (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-21T11:47:01+00:00","dateModified":"2023-07-21T11:47:01+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare IF-THEN-DO in SAS, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/se-allora-no\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/se-allora-no\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/se-allora-no\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare if-then-do in sas (con esempi)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2619"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=2619"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2619\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}