<?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: Iterate with %do loop macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558396#M155851</link>
    <description>&lt;P&gt;Thanks Paige, it works exactly like I need it to! It wasn't working for a while, but I had made a simple SAS mistake and was missing a semi-colon :).&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 May 2019 17:54:25 GMT</pubDate>
    <dc:creator>Tommy1</dc:creator>
    <dc:date>2019-05-13T17:54:25Z</dc:date>
    <item>
      <title>Iterate with %do loop macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558386#M155844</link>
      <description>&lt;P&gt;Hi SAS Community, I not very good at using macros yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a process that I run already (See below), but I have to change the model macro variable and rerun it each time I run it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let model= a /*b c d e*/;&lt;BR /&gt;&lt;BR /&gt;DATA a&amp;amp;model; &lt;BR /&gt;SET &amp;amp;model(Keep=&amp;amp;model);&lt;BR /&gt;RUN;
&lt;BR /&gt;DATA a2&amp;amp;model;
SET &amp;amp;Data2(Keep=&amp;amp;model); &lt;BR /&gt;run;
	&lt;BR /&gt;proc freq data=a&amp;amp;model noprint ;
	tables &amp;amp;model/ out=base&amp;amp;model; &lt;BR /&gt;run;
&lt;BR /&gt;proc freq data=a2&amp;amp;model noprint;
	tables &amp;amp;model/ out=current&amp;amp;model; &lt;BR /&gt;run;
&lt;BR /&gt;data finbase&amp;amp;model; set base&amp;amp;model;
		Bin=&amp;amp;model;
		Counts_Training= COUNT;
		Percent_Total_Training= PERCENT;
	drop &amp;amp;model count percent; &lt;BR /&gt;run;
&lt;BR /&gt;/*... (skipped a few steps just to make display shorter)*/&lt;BR /&gt;&lt;BR /&gt;proc print data=final2&amp;amp;i noobs label;&lt;BR /&gt;     title1 "PSI for &amp;amp;model.: &amp;amp;q &amp;amp;model &amp;amp;year ";&lt;BR /&gt;     sum counts_training percent_total_training counts_validation percent_total_validation PSI;&lt;BR /&gt;run;&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;Now I want to take want to take what I have and loop through all the values of the model macro variable.&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;%let model = a b c d e;&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;I tried following the example&amp;nbsp;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Looping-with-Variable-Names/td-p/365111" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/General-SAS-Programming/Looping-with-Variable-Names/td-p/365111&lt;/A&gt;, but I am not doing it correctly because it should finish with a proc print for each iteration and nothing is printing out. What I tried was&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;%let model= a b c d e

%macro test (list= &amp;amp;model)
%local n i;
%do n=1 %to %sysfunc(countw(&amp;amp;list));
	%let i=%scan(&amp;amp;list,&amp;amp;n);
	
DATA a&amp;amp;i;&lt;BR /&gt;SET &amp;amp;i(Keep=&amp;amp;i);&lt;BR /&gt;RUN;
	&lt;BR /&gt;DATA a2&amp;amp;i;
SET &amp;amp;Data2(Keep=&amp;amp;i); &lt;BR /&gt;run;
	&lt;BR /&gt;proc freq data=a&amp;amp;i noprint ;
	tables &amp;amp;i/ out=base&amp;amp;i; &lt;BR /&gt;run;
	&lt;BR /&gt;proc freq data=a2&amp;amp;i noprint;
	tables &amp;amp;i/ out=current&amp;amp;i; &lt;BR /&gt;run;
	&lt;BR /&gt;data finbase&amp;amp;i; &lt;BR /&gt;set base&amp;amp;i;
		Bin=&amp;amp;i;
		Counts_Training= COUNT;
		Percent_Total_Training= PERCENT;
	drop &amp;amp;i count percent; &lt;BR /&gt;run;
	&lt;BR /&gt;data fincur&amp;amp;i; &lt;BR /&gt;set current&amp;amp;i;
		Bin=&amp;amp;i;
		Counts_Validation= COUNT;
		Percent_Total_Validation= PERCENT;
	drop &amp;amp;i count percent; &lt;BR /&gt;run;
	&lt;BR /&gt;/*...*/&lt;BR /&gt;proc print data=final2&amp;amp;i noobs label;
			title1 "PSI for &amp;amp;i.: &amp;amp;q &amp;amp;i &amp;amp;year ";
			sum counts_training percent_total_training counts_validation percent_total_validation PSI;
run;

%end;
%mend;
%test;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone could help me figure what I am doing wrong and how I could loop through this that would be extremely helpful!&lt;/P&gt;&lt;P&gt;(I don't know why the formatting is appearing wierd.)&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 17:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558386#M155844</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2019-05-13T17:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate with %do loop macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558387#M155845</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let i=%scan(&amp;amp;list,&amp;amp;n,%str( ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 May 2019 17:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558387#M155845</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-13T17:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate with %do loop macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558396#M155851</link>
      <description>&lt;P&gt;Thanks Paige, it works exactly like I need it to! It wasn't working for a while, but I had made a simple SAS mistake and was missing a semi-colon :).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 17:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-with-do-loop-macro/m-p/558396#M155851</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2019-05-13T17:54:25Z</dc:date>
    </item>
  </channel>
</rss>

