<?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: Create macro variables from verctor macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784397#M250313</link>
    <description>&lt;P&gt;Essentially. But the rules are a little more complex than that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the macro variable already exists then the visible one (the one at the lowest/closest symbol tables) is updated.&amp;nbsp; That could be a GLOBAL macro variable or one local to the current macro that is running, but it might be one that is local to a macro that is running that called this macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the macro variable does not exist then one is created in the lowest symbol table.&amp;nbsp; Which might be the GLOBAL table, for example if you ran the data step outside of a macro.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 21:09:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-12-06T21:09:19Z</dc:date>
    <item>
      <title>Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784332#M250288</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define a macro variable that contain dates in form YYMM.&lt;/P&gt;
&lt;P&gt;The number of arguments in dates macro variable can be different (depends on the specific program run)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;%let dates=1903+1908+1912+2102+2105+2106;&lt;/P&gt;
&lt;P&gt;I want to create a dynamic progrmam that creates the following macro variables automtically&lt;/P&gt;
&lt;P&gt;m1=1903&lt;/P&gt;
&lt;P&gt;m2=1908&lt;/P&gt;
&lt;P&gt;m3=1912&lt;/P&gt;
&lt;P&gt;m4=2102&lt;/P&gt;
&lt;P&gt;m5=2105&lt;/P&gt;
&lt;P&gt;m6=2106&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 15:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784332#M250288</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-06T15:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784333#M250289</link>
      <description>&lt;P&gt;This can get you started&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1qvxz5u3uru7yn1nk7q64ohvwak.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1qvxz5u3uru7yn1nk7q64ohvwak.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define a macro variable that contain dates in form YYMM.&lt;/P&gt;
&lt;P&gt;The number of arguments in dates macro variable can be different (depends on the specific program run)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;%let dates=1903+1908+1912+2102+2105+2106;&lt;/P&gt;
&lt;P&gt;I want to create a dynamic progrmam that creates the following macro variables automtically&lt;/P&gt;
&lt;P&gt;m1=1903&lt;/P&gt;
&lt;P&gt;m2=1908&lt;/P&gt;
&lt;P&gt;m3=1912&lt;/P&gt;
&lt;P&gt;m4=2102&lt;/P&gt;
&lt;P&gt;m5=2105&lt;/P&gt;
&lt;P&gt;m6=2106&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 15:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784333#M250289</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-06T15:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784334#M250290</link>
      <description>&lt;P&gt;Why would want to make your program more complicated by creating so many macro variables?&lt;/P&gt;
&lt;P&gt;Just use the one you already have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dates=1903+1908+1912+2102+2105+2106;
%do index=1 %to %sysfunc(countw(&amp;amp;dates,+));
  %let date=%scan(&amp;amp;dates,&amp;amp;index,+);
  %let sasdate=%sysfunc(inputn(20&amp;amp;date,yymmn6.));
... do stuff with the string &amp;amp;DATE and the actual date &amp;amp;SASDATE ...
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS Why are you storing years using only 2 digits?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 15:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784334#M250290</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T15:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784339#M250294</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;In my work people use to write in form YYMM and not YYYYMM . (I work in Cyprus).&lt;/P&gt;
&lt;P&gt;I want to create macro vraibles&amp;nbsp; m1,m2,m3.....&lt;/P&gt;
&lt;P&gt;In your code I didn't see the index of the macro variables names.&lt;/P&gt;
&lt;P&gt;Should I put it in macro and then in _null_ data set ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dates=1903+1908+1912+2102+2105+2106;
%Macro RRR;
%do i=1 %to %sysfunc(countw(&amp;amp;dates,+));
%let m&amp;amp;i=%scan(&amp;amp;dates,&amp;amp;i,+);
 %let sasdate&amp;amp;i.=%sysfunc(inputn(20&amp;amp;&amp;amp;m&amp;amp;i..,yymmn6.));
%end;
%mend;
DATA _null_;
%RRR;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 16:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784339#M250294</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-06T16:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784341#M250295</link>
      <description>&lt;P&gt;What is it you are doing with them?&amp;nbsp; Do you really need to reference all 6 at the same time?&amp;nbsp; In general it probably will just make them harder to use to create so many macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code since it is wrapped in a macro is going to by default create LOCAL macro variables that will disappear when the macro ends.&amp;nbsp; You could add a %GLOBAL statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %global m&amp;amp;i sasdate&amp;amp;i ;
  %let m&amp;amp;i=%scan(&amp;amp;dates,&amp;amp;i,+);
  %let sasdate&amp;amp;i.=%sysfunc(inputn(20&amp;amp;&amp;amp;m&amp;amp;i..,yymmn6.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Wrapping a macro call that does not produce any SAS statements inside a DATA step is useless and just confusing to you and whoever needs to read your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do need to run a data step then you could also just use data step code to generate macro variables from your list.&amp;nbsp; Data step code is much easier to debug.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to countw("&amp;amp;dates",'+');
    call symputx(cats('m',i),scan("&amp;amp;dates",i,'+'),'g');
    call symputx(cats('sasdate',i),input(scan("&amp;amp;dates",i,'+'),yymmn4.),'g');
  end;
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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 16:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784341#M250295</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T16:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784385#M250306</link>
      <description>Thanks .&lt;BR /&gt;Will this code create global or local macro variables?&lt;BR /&gt;Can you explain why?&lt;BR /&gt;Also want to ask why did you add 'g' to scan ? &lt;BR /&gt;data _null_;&lt;BR /&gt;do i=1 to countw("&amp;amp;amp;dates",'+');&lt;BR /&gt;call symputx(cats('m',i),scan("&amp;amp;amp;dates",i,'+'),'g');&lt;BR /&gt;call symputx(cats('sasdate',i),input(scan("&amp;amp;amp;dates",i,'+'),yymmn4.),'g');&lt;BR /&gt;end;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 06 Dec 2021 20:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784385#M250306</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-06T20:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784387#M250307</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: What value is the code using for the SYMBOL-TABLE optional argument?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 20:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784387#M250307</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T20:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784393#M250310</link>
      <description>Great and thanks.&lt;BR /&gt;So the 'g' symbol make it global macro variables and without 'g' will get local ?</description>
      <pubDate>Mon, 06 Dec 2021 20:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784393#M250310</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-06T20:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables from verctor macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784397#M250313</link>
      <description>&lt;P&gt;Essentially. But the rules are a little more complex than that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the macro variable already exists then the visible one (the one at the lowest/closest symbol tables) is updated.&amp;nbsp; That could be a GLOBAL macro variable or one local to the current macro that is running, but it might be one that is local to a macro that is running that called this macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the macro variable does not exist then one is created in the lowest symbol table.&amp;nbsp; Which might be the GLOBAL table, for example if you ran the data step outside of a macro.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-from-verctor-macro-variable/m-p/784397#M250313</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T21:09:19Z</dc:date>
    </item>
  </channel>
</rss>

