<?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: macro in loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545362#M150849</link>
    <description>&lt;P&gt;Thanks for the solution, this is not what I want, I need it to be done in data step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combine;&lt;BR /&gt;%let name1=diabetes;&lt;BR /&gt;do i=1 to 12;&lt;BR /&gt;i=put(i,z2.);%let month_input=%sysfunc(putn(i, z2.));&lt;BR /&gt;%put &amp;amp;month_input;&lt;BR /&gt;&lt;BR /&gt;%let name=%sysfunc(catx(&amp;amp;name1., &amp;amp;month_input));&lt;/P&gt;&lt;P&gt;%put &amp;amp;name.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set &amp;amp;name;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other word I need to combine 12 datasets which name ended with 2-digit month, however the &amp;nbsp;putn is not functional in data step.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Mar 2019 19:47:41 GMT</pubDate>
    <dc:creator>fsuzhang</dc:creator>
    <dc:date>2019-03-22T19:47:41Z</dc:date>
    <item>
      <title>macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545346#M150842</link>
      <description>&lt;P&gt;though the following command works well&lt;/P&gt;&lt;P&gt;%let month_input=%sysfunc(putn(1,z2.));&lt;BR /&gt;%put &amp;amp;month_input;&lt;/P&gt;&lt;P&gt;the result is 02 as expected,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however when I put it into loop, the putn is not accepted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combine;&lt;BR /&gt;do i=1 to 12;&lt;BR /&gt;%let month_input=%sysfunc(putn(i,z2.));&lt;BR /&gt;%put &amp;amp;month_input;&lt;BR /&gt;month=&amp;amp;month_input;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545346#M150842</guid>
      <dc:creator>fsuzhang</dc:creator>
      <dc:date>2019-03-22T19:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545347#M150843</link>
      <description>&lt;P&gt;You cannot apply a numeric format to the letter I.&lt;/P&gt;
&lt;P&gt;You forgot the &amp;amp;.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545347#M150843</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-22T19:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545348#M150844</link>
      <description>&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f4f4f4; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;%let month_input=%sysfunc(putn(&amp;amp;i.,z2.));&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545348#M150844</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-03-22T19:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545351#M150846</link>
      <description>Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;this is the error message got using %let month_input=%sysfunc(putn(&amp;amp;i.,z2.));</description>
      <pubDate>Fri, 22 Mar 2019 19:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545351#M150846</guid>
      <dc:creator>fsuzhang</dc:creator>
      <dc:date>2019-03-22T19:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545355#M150848</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267606"&gt;@fsuzhang&lt;/a&gt;&amp;nbsp; Are you trying to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month_input=%sysfunc(putn(1,z2.));
%put &amp;amp;month_input;

data combine;
do i=1 to 12;
month_input=putn(i, "z2.");
put month_input= ;
month=month_input;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;OR&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*macro loop*/

%macro putn;
%do i=1 %to 12;
%let month_input=%sysfunc(putn(&amp;amp;i, z2));
%put month=&amp;amp;month_input;
%end;
%mend putn;

%putn&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545355#M150848</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-22T19:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545362#M150849</link>
      <description>&lt;P&gt;Thanks for the solution, this is not what I want, I need it to be done in data step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combine;&lt;BR /&gt;%let name1=diabetes;&lt;BR /&gt;do i=1 to 12;&lt;BR /&gt;i=put(i,z2.);%let month_input=%sysfunc(putn(i, z2.));&lt;BR /&gt;%put &amp;amp;month_input;&lt;BR /&gt;&lt;BR /&gt;%let name=%sysfunc(catx(&amp;amp;name1., &amp;amp;month_input));&lt;/P&gt;&lt;P&gt;%put &amp;amp;name.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set &amp;amp;name;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other word I need to combine 12 datasets which name ended with 2-digit month, however the &amp;nbsp;putn is not functional in data step.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545362#M150849</guid>
      <dc:creator>fsuzhang</dc:creator>
      <dc:date>2019-03-22T19:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545370#M150852</link>
      <description>&lt;P&gt;Thanks all guys, I solve it finally using macro outside data step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let name1=diabetes_;&lt;BR /&gt;%let year=2018;&lt;BR /&gt;%macro putn;&lt;BR /&gt;data combine;&lt;BR /&gt;%do i=1 %to 12;&lt;BR /&gt;%let month_input=%sysfunc(putn(&amp;amp;i, z2));&lt;BR /&gt;%put month=&amp;amp;month_input;&lt;BR /&gt;%let name= &amp;amp;name1&amp;amp;month_input.&amp;amp;year;&lt;BR /&gt;%put &amp;amp;name;&lt;/P&gt;&lt;P&gt;date=&amp;amp;month_input.&amp;amp;year.;&lt;BR /&gt;set &amp;amp;name.;&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;%mend putn;&lt;/P&gt;&lt;P&gt;%putn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I am still wondering with why the following code not working&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data null;&lt;BR /&gt;do i=1 to 12;&lt;BR /&gt;%let month_input=%sysfunc(putn(i, z2.));&lt;BR /&gt;%put &amp;amp;month_input;&lt;/P&gt;&lt;P&gt;month=&amp;amp;month_input;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 20:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545370#M150852</guid>
      <dc:creator>fsuzhang</dc:creator>
      <dc:date>2019-03-22T20:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545375#M150855</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267606"&gt;@fsuzhang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;but I am still wondering with why the following code not working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data null;&lt;BR /&gt;do i=1 to 12;&lt;BR /&gt;%let month_input=%sysfunc(putn(i, z2.));&lt;BR /&gt;%put &amp;amp;month_input;&lt;/P&gt;
&lt;P&gt;month=&amp;amp;month_input;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because the letter I is NOT a number.&lt;/P&gt;
&lt;P&gt;It is also NOT the name of variable when the macro processor is running.&lt;/P&gt;
&lt;P&gt;The macro processor is used to process text.&amp;nbsp; The text that it generates is THEN passed to the SAS compiler to interpret as code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if you could have could have gotten the macro processor to generate the macro variable MONTH_INPUT its value would have been resolved by the macro processor BEFORE the code is passed to SAS to run.&lt;/P&gt;
&lt;P&gt;So you are trying to generate a data step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data out;
do i=1 to 12;
  month=12;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 20:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545375#M150855</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-22T20:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: macro in loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545380#M150856</link>
      <description>&lt;P&gt;Do not use macro functions in general to modify or attempt to use&amp;nbsp;dataset variables. The timing is wrong as to when/what executes and the macro processor does not see the data vector.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to create a character variable with leading 0 or a numeric variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data combine;
do i=1 to 12;
   monthchar= put(i,z2.);
   output;
end;
run;&lt;/PRE&gt;
&lt;P&gt;If you create variable in a dataset there are not leading zeroes unless 1) the values are between (0,1) such as 0.25 :example:&lt;/P&gt;
&lt;PRE&gt;data example;
   x=0.25;
   y=0004;
run;&lt;/PRE&gt;
&lt;P&gt;OR you apply the Z format to a variable:&lt;/P&gt;
&lt;PRE&gt;data example;
   x=0.25;
   y=0004;
   format y z4.;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 21:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-in-loop/m-p/545380#M150856</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-22T21:17:18Z</dc:date>
    </item>
  </channel>
</rss>

