<?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: problem in looping macro in sas programming in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133285#M27104</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I've understood your macro function definition it processes one data set only, so maybe you could call your macro 3 times, each time supplying the different data set name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To automatically loop through a space-separated list of data set names then you could use something like the following, based on code supplied by @Tom:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%macro infoid_loop(datalist);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %local i date ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %do i=1 %to %sysfunc(countw(&amp;amp;datalist,%str( )));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let dataset=%scan(&amp;amp;datalist,&amp;amp;i,%str( ));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %infoid(&amp;amp;dataset,arg2,arg3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%mend infoid_loop;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then invoke it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%infoid_loop(set_a set b set_c,arg2,arg3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One thing I noticed is that your macro function definition allows 3 parameters to be passed to it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro infoid(data,xvar,yvar);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but you are only calling it with 2 parameters:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%infoid(&amp;amp;xvar,gbi);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are still having problems then please post the log with any error messages showing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Nov 2013 13:03:36 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2013-11-06T13:03:36Z</dc:date>
    <item>
      <title>problem in looping macro in sas programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133282#M27101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hay, i have some problem. i want to looping all macro, and expected output is i have 3 dataset output from proc freq (test_education ; test_residence and test_monthly_income)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but my code works for the last variable in macro %LET (monthly_income)..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is it possible to me if i want to automatically create 3 dataset in row.. how is it possible? is my sas code is wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sorry for my bad english.. here i attach the code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro infoid(data,xvar,yvar);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data _null_;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if 0 then set &amp;amp;data.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array _x&lt;/STRONG&gt;&lt;LI&gt;&lt;STRONG&gt; &amp;amp;xvar;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array _y&lt;/STRONG&gt;&lt;LI&gt;&lt;STRONG&gt; &amp;amp;yvar;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call symput("nx", trim(left(put(dim(_x),12.))));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call symput("ny", trim(left(put(dim(_y),12.))));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;length _mname _vname $20;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do _i=1 to dim(_x);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_mname='x'||trim(left(put(_i,12.)));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call execute('%global '||_mname);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call vname(_x[_i],_vname);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call symput(_mname,trim(_vname));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do _i=1 to dim(_y);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_mname='y'||trim(left(put(_i,12.)));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call execute('%global '||_mname);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call vname(_y[_i],_vname);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call symput(_mname,trim(_vname));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;stop;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=&amp;amp;data.(keep= &amp;amp;&amp;amp;x&amp;amp;nx gbi ) out=test_&amp;amp;&amp;amp;x&amp;amp;x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by &amp;amp;&amp;amp;x&amp;amp;nx;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let xvar = education_level residence monthly_income ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%infoid(&amp;amp;xvar,gbi);&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Nov 2013 07:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133282#M27101</guid>
      <dc:creator>meres</dc:creator>
      <dc:date>2013-11-06T07:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: problem in looping macro in sas programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133283#M27102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm confused, you have three parameters in the macro definition, but you only seem to use two of them, and I guess that your &amp;amp;xvar will be received as &amp;amp;data - is that what you want?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Nov 2013 12:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133283#M27102</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-11-06T12:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: problem in looping macro in sas programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133284#M27103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is no actual macro loop coded in that macro.&lt;/P&gt;&lt;P&gt;It looks like you want to put the PROC SORT step inside of a %DO loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Nov 2013 12:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133284#M27103</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-06T12:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: problem in looping macro in sas programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133285#M27104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I've understood your macro function definition it processes one data set only, so maybe you could call your macro 3 times, each time supplying the different data set name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To automatically loop through a space-separated list of data set names then you could use something like the following, based on code supplied by @Tom:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%macro infoid_loop(datalist);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %local i date ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %do i=1 %to %sysfunc(countw(&amp;amp;datalist,%str( )));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let dataset=%scan(&amp;amp;datalist,&amp;amp;i,%str( ));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %infoid(&amp;amp;dataset,arg2,arg3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; %end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;%mend infoid_loop;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then invoke it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%infoid_loop(set_a set b set_c,arg2,arg3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One thing I noticed is that your macro function definition allows 3 parameters to be passed to it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro infoid(data,xvar,yvar);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but you are only calling it with 2 parameters:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%infoid(&amp;amp;xvar,gbi);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are still having problems then please post the log with any error messages showing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Nov 2013 13:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-in-looping-macro-in-sas-programming/m-p/133285#M27104</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-11-06T13:03:36Z</dc:date>
    </item>
  </channel>
</rss>

