<?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: Trying to use SAS macro to create variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628490#M185729</link>
    <description>&lt;P&gt;I am failing to understand why you would want to loop from 0 to 76 when you apparently want var names suffixes from 1 to 77?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I were to assume you want a leading zero for values that are single digit numbers, you could address that with a Z format to standardize that, i.e&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*First Check the values in the log to see if this is what you are after*/
%macro test123;
%do i= 1 %to 77;
%put %sysfunc(putn(&amp;amp;i,z2.));
%end;
%mend test123;

/*If the above is what are after then plug that*/

%macro test123;
%do i= 1 %to 77;
if ((Fdevyr - Flye) * 4 + int((Fdevm - 1) / 3) - int((FM - 1) / 3)) = &amp;amp;i. then do;
if component = 'Counts' then Amount_%sysfunc(putn(&amp;amp;i,z2.)) = count;
end;
%end;
%mend test123;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 29 Feb 2020 22:24:32 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-02-29T22:24:32Z</dc:date>
    <item>
      <title>Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628485#M185724</link>
      <description>&lt;P&gt;HI, I'm trying to use sas macro to create a dynamic variable name. Below is the snippet of my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test123;&lt;BR /&gt;%do i= 0 %to 76;&lt;BR /&gt;if ((Fdevyr - Flye) * 4 + int((Fdevm - 1) / 3) - int((FM - 1) / 3)) = &amp;amp;i. then do;&lt;BR /&gt;if component = 'Counts' then Amount_0&amp;amp;i. = count;&lt;BR /&gt;end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend test123;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this code creates a new Variable - Amount_00, Amount_01..upto Amount_76.and so on but instead I would like to create the variable names as Amount_01,Amount_02...Amount_77 using the above code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using&amp;nbsp;Amount_0&amp;amp;i+1 but I think that's not a valid way of using it.&lt;/P&gt;&lt;P&gt;I have tried %let j= &amp;amp;i.+1 inside my Do Loop but I think we cannot have another macro variable inside a macro.&lt;/P&gt;&lt;P&gt;I'm a beginner to SAS and any suggestions are much appreciated. Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 21:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628485#M185724</guid>
      <dc:creator>carl01</dc:creator>
      <dc:date>2020-02-29T21:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628490#M185729</link>
      <description>&lt;P&gt;I am failing to understand why you would want to loop from 0 to 76 when you apparently want var names suffixes from 1 to 77?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I were to assume you want a leading zero for values that are single digit numbers, you could address that with a Z format to standardize that, i.e&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*First Check the values in the log to see if this is what you are after*/
%macro test123;
%do i= 1 %to 77;
%put %sysfunc(putn(&amp;amp;i,z2.));
%end;
%mend test123;

/*If the above is what are after then plug that*/

%macro test123;
%do i= 1 %to 77;
if ((Fdevyr - Flye) * 4 + int((Fdevm - 1) / 3) - int((FM - 1) / 3)) = &amp;amp;i. then do;
if component = 'Counts' then Amount_%sysfunc(putn(&amp;amp;i,z2.)) = count;
end;
%end;
%mend test123;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Feb 2020 22:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628490#M185729</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-29T22:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628491#M185730</link>
      <description>&lt;P&gt;How are you using that code that macro generates?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is the macro any better than just defining an ARRAY in the data step that is using that code?&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 22:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628491#M185730</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-29T22:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628492#M185731</link>
      <description>&lt;P&gt;Something like below should do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test123;
  %do i= 1 %to 77;
    %if &amp;amp;i&amp;gt;1 %then else;
    if ((Fdevyr - Flye) * 4 + int((Fdevm - 1) / 3) - int((FM - 1) / 3)) = %eval(&amp;amp;i.-1) then
      do;
        if component = 'Counts' then
          Amount_0&amp;amp;i. = count;
      end;
  %end;
%mend test123;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Feb 2020 22:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628492#M185731</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-29T22:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628493#M185732</link>
      <description>&lt;P&gt;Thanks Patrick&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 22:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628493#M185732</guid>
      <dc:creator>carl01</dc:creator>
      <dc:date>2020-02-29T22:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628495#M185734</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314447"&gt;@carl01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Patrick&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;ehhmm... .then may-be you should mark my answer as the solution....&lt;BR /&gt;From a coding perspective using a SAS datastep array instead of macro coding is "better".&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 22:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/628495#M185734</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-29T22:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use SAS macro to create variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/629894#M186405</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I'm a beginner to SAS&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is a good justification for &lt;STRONG&gt;not&lt;/STRONG&gt; jumping into Macro.&amp;nbsp; There is huge utility in the DATA Step language without a need for any macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Far less confusing would be to use a variable based array to create the variable names &lt;FONT face="courier new,courier"&gt;amount_00-amount_76&lt;FONT face="arial,helvetica,sans-serif"&gt;.&amp;nbsp; Your complex formula would compute the index for assignment.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;

  array amts amount00-amount76;

  index = ((Fdevyr - Flye) * 4 + int((Fdevm - 1) / 3) - int((FM - 1) / 3));
  if component = 'Counts' then amts(index) = count;

run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 18:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-use-SAS-macro-to-create-variable-name/m-p/629894#M186405</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-03-05T18:03:40Z</dc:date>
    </item>
  </channel>
</rss>

