<?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: DO iteration over specifics values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488304#M287394</link>
    <description>&lt;P&gt;Mainly because you are not testing macro variable but some (possible non-existant) dataset variable named I.&amp;nbsp; Do you want the records where ID = &amp;amp;I ? Or where ID = &amp;amp;value ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have other typos in the program also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also do not want to use %qscan() to macro quote the value since you are using it as part of a dataset name there cannot be anything in it that would need macro quoting. And the macro quoting might cause issues with SAS parsing the generated code&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;It is also a lot easier to use a space as the delimiter instead of a comma since then it means you don't need to macro quote the call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to define your macro variables as local, in case the calling environment is using any of those macro variable names already.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop(values);
%local i count value;
%let count=%sysfunc(countw(&amp;amp;values,%str( )));

%do i = 1 %to &amp;amp;count;
  %let value=%scan(&amp;amp;values,&amp;amp;i,%str( ));
  %put &amp;amp;value;

  data B_&amp;amp;value;
    set A;
    where id = &amp;amp;i;
  run;
%end
%mend loop;

%loop(1 2 3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Aug 2018 18:21:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-08-20T18:21:11Z</dc:date>
    <item>
      <title>%DO iteration over specifics values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488299#M287393</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to filter a data set several times and execute a specific proc in each one (that proc not support the by statement). I'm trying to write a do macro which goes over specific values (that I would use to filter the data and execute the proc). I tried the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop(values);
let count=%sysfunc(countw(&amp;amp;values));

%do i = 1 %to &amp;amp;count;
 %let value=%qscan(&amp;amp;values,&amp;amp;i,%str(,));                                                                                            
 %put &amp;amp;value; 

 data B_&amp;amp;values;
 set A;
 where id = i;
 run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
%end


%mend 

%loop(%str(1,2,3)) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I intended to get as a result 3 data sets (B_1, B_2 and B_3) which I would use to execute my proc (inside the do loop). But it isn't working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Someone can help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 18:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488299#M287393</guid>
      <dc:creator>brunomsl</dc:creator>
      <dc:date>2018-08-20T18:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: DO iteration over specifics values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488304#M287394</link>
      <description>&lt;P&gt;Mainly because you are not testing macro variable but some (possible non-existant) dataset variable named I.&amp;nbsp; Do you want the records where ID = &amp;amp;I ? Or where ID = &amp;amp;value ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have other typos in the program also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also do not want to use %qscan() to macro quote the value since you are using it as part of a dataset name there cannot be anything in it that would need macro quoting. And the macro quoting might cause issues with SAS parsing the generated code&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;It is also a lot easier to use a space as the delimiter instead of a comma since then it means you don't need to macro quote the call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to define your macro variables as local, in case the calling environment is using any of those macro variable names already.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop(values);
%local i count value;
%let count=%sysfunc(countw(&amp;amp;values,%str( )));

%do i = 1 %to &amp;amp;count;
  %let value=%scan(&amp;amp;values,&amp;amp;i,%str( ));
  %put &amp;amp;value;

  data B_&amp;amp;value;
    set A;
    where id = &amp;amp;i;
  run;
%end
%mend loop;

%loop(1 2 3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 18:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488304#M287394</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-20T18:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: DO iteration over specifics values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488366#M287395</link>
      <description>&lt;P&gt;In general, looping of this sort is not a good programming method in SAS. Rather than create many individual data sets by ID, most programming is much easier in SAS leaving everything in one large data set and then using BY statements in your analysis.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 21:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488366#M287395</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-20T21:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: %DO iteration over specifics values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488373#M287396</link>
      <description>&lt;P&gt;Is this the same question as this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Macro-filter/m-p/488359" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Macro-filter/m-p/488359&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 21:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-iteration-over-specifics-values/m-p/488373#M287396</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-20T21:35:11Z</dc:date>
    </item>
  </channel>
</rss>

