<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961462#M374821</link>
    <description>&lt;P&gt;Another example of using a macro when you don't need a macro. You can obtain the same without macros, using a BY statement in PROC MEANS. In other words, a terrible question, and the student comes away from this class thinking "When I need to get statistics by year, I can do this via a macro!" which is completely the wrong lesson to learn.&lt;/P&gt;</description>
    <pubDate>Mon, 10 Mar 2025 17:50:05 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-03-10T17:50:05Z</dc:date>
    <item>
      <title>Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the list.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961459#M374818</link>
      <description>&lt;P&gt;Level 2 Practice: Using a %DO %UNTIL Loop&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;m104p11.sas&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Modify the&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Storms&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;macro to accept a space-separated list of years. Use a %DO %UNTIL loop and the %SCAN macro function to generate a report for each year in the list.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;here is the code I have executed that is giving an error message (shown below the code):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro storms(year);&lt;BR /&gt;%let i=1;&lt;BR /&gt;%let yr=%scan(&amp;amp;year, &amp;amp;i);&lt;BR /&gt;%do %Until (&amp;amp;yr eq) ;&lt;BR /&gt;title "&amp;amp;yr Storms";&lt;BR /&gt;proc means data=mc1.storm_final n min mean max maxdec=0;&lt;BR /&gt;var MaxWindMPH MinPressure;&lt;BR /&gt;where season=&amp;amp;yr;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let i = %eval(&amp;amp;i+1);&lt;BR /&gt;%let yr=%scan(&amp;amp;year, &amp;amp;i);&lt;BR /&gt;%end;&lt;BR /&gt;title;&lt;BR /&gt;%mend storms;&lt;/P&gt;&lt;P&gt;%storms&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hmlong25_0-1741620139059.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105321iC43B75DAA6E81822/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hmlong25_0-1741620139059.png" alt="hmlong25_0-1741620139059.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 16:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961459#M374818</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-03-10T16:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961461#M374820</link>
      <description>&lt;P&gt;The first thing I see is that your code does not provide a space-delimited list of years for the macro to work with. If you provide some values like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%storms(1980 1990 2000 2010)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;your&amp;nbsp;macro&amp;nbsp;will&amp;nbsp;generate&amp;nbsp;a&amp;nbsp;report&amp;nbsp;for&amp;nbsp;each&amp;nbsp;year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 17:43:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961461#M374820</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2025-03-10T17:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961462#M374821</link>
      <description>&lt;P&gt;Another example of using a macro when you don't need a macro. You can obtain the same without macros, using a BY statement in PROC MEANS. In other words, a terrible question, and the student comes away from this class thinking "When I need to get statistics by year, I can do this via a macro!" which is completely the wrong lesson to learn.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 17:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961462#M374821</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-10T17:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961463#M374822</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see what the macro is generating you can submit the following line of code before invoking the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can see if there are any issues with the generated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if variable &lt;FONT face="courier new,courier"&gt;season&lt;/FONT&gt; is character then remember to use double quotes around the &lt;FONT face="courier new,courier"&gt;&amp;amp;yr&lt;/FONT&gt; value in the &lt;FONT face="courier new,courier"&gt;where&lt;/FONT&gt; statement, i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where season="&amp;amp;yr";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're still having issues then please share the whole log (with the &lt;FONT face="courier new,courier"&gt;mprint&lt;/FONT&gt; option) by copying and then pasting it here using the Insert Code icon "&amp;lt;/&amp;gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 17:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961463#M374822</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2025-03-10T17:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961465#M374823</link>
      <description>&lt;P&gt;Your code is truncated perhaps??&lt;/P&gt;
&lt;P&gt;You defined the macro STORMS to accept an input parameter.&amp;nbsp; But you did not pass it any value for the parameter in your call to the macro.&amp;nbsp; Try either one of these macro calls instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%storms(2019 2020)
%storms(year=2019 2020)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember that you can pass values to a macro by NAME even for parameters that you defined to allow the values to passed by position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your code is NOT expecting a space delimited list.&amp;nbsp; Instead it is expecting a list that is delimited by any of the default delimiters that the %SCAN() function uses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;If you use the %SCAN function with only two arguments, then the default delimiters depend on whether your computer uses ASCII or EBCDIC characters.&lt;/P&gt;
&lt;UL class="xisDoc-listUnordered"&gt;
&lt;LI class="xisDoc-item"&gt;If your computer uses ASCII characters, then the default delimiters are as follows:
&lt;P class="xisDoc-paragraph"&gt;blank ! $ % &amp;amp; ( ) * + , - . / ; &amp;lt; ^¦&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;In ASCII environments that do not contain the ^ character, the %SCAN function uses the ~ character instead.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;If your computer uses EBCDIC characters, then the default delimiters are as follows:
&lt;P class="xisDoc-paragraph"&gt;blank ! $ % &amp;amp; ( ) * + , - . / ; &amp;lt; ¬ | ¢¦&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To make it use only SPACE as the delimiter update this line (in both places it appears) in your macro definition.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yr=%scan(&amp;amp;year, &amp;amp;i, %str( ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 18:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961465#M374823</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-10T18:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961483#M374832</link>
      <description>&lt;BR /&gt;Thank you!</description>
      <pubDate>Mon, 10 Mar 2025 19:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961483#M374832</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-03-10T19:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961484#M374833</link>
      <description>: )</description>
      <pubDate>Mon, 10 Mar 2025 20:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961484#M374833</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-03-10T20:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961485#M374834</link>
      <description>Thank you!</description>
      <pubDate>Mon, 10 Mar 2025 20:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961485#M374834</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-03-10T20:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why do i use the %DO %UNTIL loop with the %SCAN macro function make a report each year in the li</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961486#M374835</link>
      <description>Great! Thanks! I'm glad it's that simple</description>
      <pubDate>Mon, 10 Mar 2025 20:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-do-i-use-the-DO-UNTIL-loop-with-the-SCAN-macro-function-make/m-p/961486#M374835</guid>
      <dc:creator>hmlong25</dc:creator>
      <dc:date>2025-03-10T20:04:11Z</dc:date>
    </item>
  </channel>
</rss>

