

{"id":11393,"date":"2018-03-22T10:03:26","date_gmt":"2018-03-22T10:03:26","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=11393"},"modified":"2021-05-09T13:16:53","modified_gmt":"2021-05-09T07:46:53","slug":"sas-loop","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/sas-loop\/","title":{"rendered":"SAS Loop &#8211; Do Loop, Do While &amp; Do Until loop in SAS"},"content":{"rendered":"<p>In this <strong>SAS Programming Tutorial<\/strong>, we discuss SAS Loop, like all other programming languages, SAS also has Loops.<\/p>\n<p>Moreover, we see three important types of loops in SAS: SAS DO Loop, SAS DO WHILE loop, and SAS DO UNTIL Loop with their Syntax and examples for programming. Let us understand SAS Loop with some example.<\/p>\n<h2>What is SAS Loop<\/h2>\n<p>Whenever we hear the word programming, the first thought that comes to our mind is large blocks of code, written using loops. Looping is the first step that a programming beginner learns.<\/p>\n<p>Loops are an important part of a program because they help us to repeat calculations multiple numbers of times for a given set of parameters.<\/p>\n<p>Different languages use different keywords to define the iteration statement. The most well-known statement is the &#8220;for loop,&#8221; which is used by C\/C++, MATLAB, <strong>R<\/strong>, and other languages. Older languages, such as FORTRAN and SAS, call the iteration statement a &#8220;do loop,&#8221; but it is exactly the same concept.<\/p>\n<h2>Types of Loops in SAS<\/h2>\n<p>There are 3 types of SAS Loops, let&#8217;s discuss them one by one:<\/p>\n<h3>a. SAS DO Loop<\/h3>\n<p>It has the syntax\u00a0 of Do Loop in SAS<br \/>\nDO\u00a0<em>value<\/em>\u00a0=\u00a0<em>start<\/em>\u00a0TO\u00a0<em>stop<\/em><br \/>\n<strong>SAS Do Loop Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">data A;\u00a0\r\ndo i = 1 to 4;\u00a0\u00a0\u00a0\r\ny = i**2; \/* values are 2, 5, 9, 16, 25 *\/\u00a0\u00a0\r\noutput;\u00a0\r\nend;\u00a0\r\nrun;<\/pre>\n<p>The END statement marks the end of the SAS loop.<br \/>\nBy default, each iteration of a DO statement increments the value of the counter by 1, but you can use the BY option to increment the counter by other amounts, including non-integer amounts.<\/p>\n<p>For example, each iteration of the following DATA step increments the value\u00a0I\u00a0by 0.3:<\/p>\n<pre class=\"EnlighterJSRAW\">data A;\r\ndo i = 1 to 5 by 0.3;\u00a0\u00a0\r\ny = i**2; \/* values are 1, 2.25, 4, ..., 16, 20.25, 25 *\/\u00a0\r\noutput;\r\nend;\u00a0\r\nrun;<\/pre>\n<p>&nbsp;<\/p>\n<h3>b. SAS DO WHILE and DO UNTIL<\/h3>\n<p>Sometimes we will want to stop iterating if a certain condition is met. There are two ways to do this: you can use the WHILE clause to iterate\u00a0<em>as long as<\/em>\u00a0a certain condition holds, or you can use the UNTIL clause to iterate\u00a0<em>until<\/em>\u00a0a certain condition holds.<\/p>\n<p>You can use the DO statement with a WHILE clause to iterate while a condition is true. The condition is checked before each iteration, which implies that you should intialize the stopping condition prior to the loop.<\/p>\n<p>The following statements extend the DATA step example and iterate as long as the value of\u00a0y\u00a0is less than 20. When\u00a0i=4, the WHILE condition is not satisfied, so the loop iterates again.<\/p>\n<pre class=\"EnlighterJSRAW\">data A;\r\n\u00a0y = 0;\u00a0\r\ndo i = 1 to 5 by 0.5 while(y &lt; 20);\u00a0\u00a0\u00a0\r\ny = i**2; \/* values are 1, 2.25, 4, ..., 16, 20.5 *\/\u00a0\r\noutput;\u00a0\r\nend;\u00a0\r\nrun;<\/pre>\n<p>You can use the DO statement with a UNTIL clause to iterate until a condition becomes true. The UNTIL condition is evaluated at the end of the loop so it does not need to be initialized.<\/p>\n<p>It is worth noting that a DO loop with a UNTIL clause\u00a0<em>always executes at least one time<\/em>\u00a0because the condition evaluates at the end of the loop. To prevent such behavior, you can use a DO loop with a WHILE clause.<\/p>\n<h2>Conclusion<\/h2>\n<p>Hence, we learn SAS Loop, types of Loops in SAS: SAS Do Loop, SAS Do While loop, SAS Do Until Loop with their example and syntax.<\/p>\n<p>In conclusion, we think these were similar to the loops you learned in other languages, and easier too. Such is the beauty of this language. For any doubts, please comment in the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this SAS Programming Tutorial, we discuss SAS Loop, like all other programming languages, SAS also has Loops. Moreover, we see three important types of loops in SAS: SAS DO Loop, SAS DO WHILE&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":11469,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[8411,12009,12010,12011,12013,12014,12070,14095,14096,14097,15078,15929],"class_list":["post-11393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sas","tag-loop-in-sas","tag-sas-do-loop","tag-sas-do-loop-example","tag-sas-do-until-loop","tag-sas-do-while-loop","tag-sas-do-while-loop-example","tag-sas-loops","tag-syntax-of-sas-do-loop","tag-syntax-of-sas-do-until-loop","tag-syntax-of-sas-do-while-loop","tag-types-of-loops-in-sas","tag-what-is-sas-loop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SAS Loop - Do Loop, Do While &amp; Do Until loop in SAS - DataFlair<\/title>\n<meta name=\"description\" content=\"What is SAS Loop,types of Loops in SAS,DO Loop,DO WHILE loop,DO UNTIL Loop in SAS,SAS Do loop example,SAS Do while loop example,SAS Do UNTIL Loop example\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/sas-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SAS Loop - Do Loop, Do While &amp; Do Until loop in SAS - DataFlair\" \/>\n<meta property=\"og:description\" content=\"What is SAS Loop,types of Loops in SAS,DO Loop,DO WHILE loop,DO UNTIL Loop in SAS,SAS Do loop example,SAS Do while loop example,SAS Do UNTIL Loop example\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/sas-loop\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-22T10:03:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:46:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Loop-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SAS Loop - Do Loop, Do While &amp; Do Until loop in SAS - DataFlair","description":"What is SAS Loop,types of Loops in SAS,DO Loop,DO WHILE loop,DO UNTIL Loop in SAS,SAS Do loop example,SAS Do while loop example,SAS Do UNTIL Loop example","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:\/\/data-flair.training\/blogs\/sas-loop\/","og_locale":"en_US","og_type":"article","og_title":"SAS Loop - Do Loop, Do While &amp; Do Until loop in SAS - DataFlair","og_description":"What is SAS Loop,types of Loops in SAS,DO Loop,DO WHILE loop,DO UNTIL Loop in SAS,SAS Do loop example,SAS Do while loop example,SAS Do UNTIL Loop example","og_url":"https:\/\/data-flair.training\/blogs\/sas-loop\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-03-22T10:03:26+00:00","article_modified_time":"2021-05-09T07:46:53+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Loop-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"SAS Loop &#8211; Do Loop, Do While &amp; Do Until loop in SAS","datePublished":"2018-03-22T10:03:26+00:00","dateModified":"2021-05-09T07:46:53+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/"},"wordCount":543,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Loop-01.jpg","keywords":["Loop in SAS","SAS DO Loop","SAS DO Loop example","SAS DO UNTIL Loop","SAS DO WHILE loop","SAS DO WHILE loop example","SAS Loops","Syntax of SAS DO Loop","Syntax of SAS DO Until loop","Syntax of SAS DO WHILE loop","Types of Loops in SAS","What is SAS Loop"],"articleSection":["SAS Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/sas-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/","url":"https:\/\/data-flair.training\/blogs\/sas-loop\/","name":"SAS Loop - Do Loop, Do While &amp; Do Until loop in SAS - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Loop-01.jpg","datePublished":"2018-03-22T10:03:26+00:00","dateModified":"2021-05-09T07:46:53+00:00","description":"What is SAS Loop,types of Loops in SAS,DO Loop,DO WHILE loop,DO UNTIL Loop in SAS,SAS Do loop example,SAS Do while loop example,SAS Do UNTIL Loop example","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/sas-loop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Loop-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/SAS-Loop-01.jpg","width":1200,"height":628,"caption":"Introduction to SAS Loop"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/sas-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"garbage collection algorithm in data structure","item":"https:\/\/data-flair.training\/blogs\/tag\/garbage-collection-algorithm-in-data-structure\/"},{"@type":"ListItem","position":3,"name":"SAS Loop &#8211; Do Loop, Do While &amp; Do Until loop in SAS"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=11393"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11393\/revisions"}],"predecessor-version":[{"id":93953,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11393\/revisions\/93953"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/11469"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=11393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=11393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=11393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}