<?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 Performing a do loop over a list of values in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417765#M26896</link>
    <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm following the steps in the above example to attempt to create a macro which will read over various values. However, I'm running into trouble.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want my code to read in the following values (1e, 1f etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then spit out 7 new datasets where they would be called&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test1e , test1f, test1g etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro px;

%let value = 1e 1f 1g 1h 1b 1a 1c;


%local i next_value;
%let i=1;
%do %while (%scan(&amp;amp;value, &amp;amp;i) ne );
   %let next_value = %scan(&amp;amp;value, &amp;amp;i);
   %let i = %eval(&amp;amp;i + 1);
%end;

   data test&amp;amp;value;
set table_&amp;amp;value;run;
%mend;

%px;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I'm running into the following issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the macro variable "VALUE".
44          test1e 1f 1g 1h 1b 1a 1c
                   _     _     _
                   22    22    22
                   200   200   200
                      _     _     _
                      22    22    22
                      200   200   200
SYMBOLGEN:  Macro variable VALUE resolves to 1e 1f 1g 1h 1b 1a 1c
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.  

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the macro variable "VALUE".
44          table_1e 1f 1g 1h 1b 1a 1c
                     _     _     _
                     22    22    22
                     200   200   200
                        _     _     _
                        22    22    22
                        200   200   200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY, 
              KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It doesn't seem to be looping over things correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any input would be great&lt;/P&gt;</description>
    <pubDate>Fri, 01 Dec 2017 15:28:20 GMT</pubDate>
    <dc:creator>Sean_OConnor</dc:creator>
    <dc:date>2017-12-01T15:28:20Z</dc:date>
    <item>
      <title>Performing a do loop over a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417765#M26896</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm following the steps in the above example to attempt to create a macro which will read over various values. However, I'm running into trouble.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want my code to read in the following values (1e, 1f etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then spit out 7 new datasets where they would be called&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;test1e , test1f, test1g etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro px;

%let value = 1e 1f 1g 1h 1b 1a 1c;


%local i next_value;
%let i=1;
%do %while (%scan(&amp;amp;value, &amp;amp;i) ne );
   %let next_value = %scan(&amp;amp;value, &amp;amp;i);
   %let i = %eval(&amp;amp;i + 1);
%end;

   data test&amp;amp;value;
set table_&amp;amp;value;run;
%mend;

%px;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I'm running into the following issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the macro variable "VALUE".
44          test1e 1f 1g 1h 1b 1a 1c
                   _     _     _
                   22    22    22
                   200   200   200
                      _     _     _
                      22    22    22
                      200   200   200
SYMBOLGEN:  Macro variable VALUE resolves to 1e 1f 1g 1h 1b 1a 1c
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.  

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the macro variable "VALUE".
44          table_1e 1f 1g 1h 1b 1a 1c
                     _     _     _
                     22    22    22
                     200   200   200
                        _     _     _
                        22    22    22
                        200   200   200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY, 
              KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.  

ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It doesn't seem to be looping over things correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any input would be great&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 15:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417765#M26896</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-12-01T15:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Performing a do loop over a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417768#M26897</link>
      <description>&lt;P&gt;Why did you bother to create next_value if you weren't going to use it?&lt;/P&gt;
&lt;P&gt;I think that is the macro variable you meant to use instead of value (which has 5 spaces in the middle) in the data step.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 15:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417768#M26897</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-01T15:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Performing a do loop over a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417770#M26899</link>
      <description>&lt;P&gt;&amp;amp;VALUE is constant.&amp;nbsp; &amp;amp;NEXT_VALUE is what changes each time through the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whatever it is you want to generate as a SAS program, it has to be inside the %DO loop, not outside.&amp;nbsp; And it should refer to &amp;amp;NEXT_VALUE instead of &amp;amp;VALUE.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 15:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417770#M26899</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-01T15:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Performing a do loop over a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417771#M26900</link>
      <description>&lt;P&gt;Look at what you macro code resolves to - remember macro does&amp;nbsp;&lt;STRONG&gt;nothing&lt;/STRONG&gt; but create base SAS code:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test&lt;SPAN class="token operator"&gt;1e 1f 1g 1h 1b 1a 1c&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;  set table_1e 1f 1g 1h 1b 1a 1c;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does that look right to you?&amp;nbsp; Maybe you meant to use next_value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, and the usual word of warning, macro can be helpful in some select occasions, however it is not a replacement for base SAS.&amp;nbsp; If you find yourself doing loops and lists of values in macro, then 90% of the time you are doing something wrong.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 15:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417771#M26900</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-01T15:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Performing a do loop over a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417772#M26901</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand correctly what you're trying to do, your ordering of SAS statements is a bit off, and you use the original long string &amp;amp;VALUE as the dataset name.&amp;nbsp;The %do loop ends without actually doing anything besides incrementing i and creating next_value macro variable. I assume for purposes of the example, the input dataset is exactly the same as the output dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro px;

%let value = 1e 1f 1g 1h 1b 1a 1c;


%local i next_value;
%let i=1;
%do %while (%scan(&amp;amp;value, &amp;amp;i) ne );
   %let next_value = %scan(&amp;amp;value, &amp;amp;i);

   data test&amp;amp;next_value;
set table_&amp;amp;next_value;run;
%let i = %eval(&amp;amp;i + 1);

%end;

%mend;

%px;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 15:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Performing-a-do-loop-over-a-list-of-values/m-p/417772#M26901</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2017-12-01T15:40:40Z</dc:date>
    </item>
  </channel>
</rss>

