<?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 multiple macro vars based on data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902280#M356553</link>
    <description>&lt;P&gt;%put &amp;amp;&amp;amp;m&amp;amp;n; doesn't work because your macro variable &amp;amp;n doesn't contain a number but a fullstop (="missing").&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1699515813242.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89576i6AC96124888C5063/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1699515813242.png" alt="Patrick_0-1699515813242.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you look at your first data step you'll see why that happens&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1699515876582.png" style="width: 617px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89577i161449DF0B22212A/image-dimensions/617x199?v=v2" width="617" height="199" role="button" title="Patrick_1-1699515876582.png" alt="Patrick_1-1699515876582.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I guess what you intended to do but then missed during development was to use variable N instead of COUNTER to populate macro variable &amp;amp;n&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1699516032230.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89578i7C99DD2D21DD3D83/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_2-1699516032230.png" alt="Patrick_2-1699516032230.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2023 07:48:25 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-11-09T07:48:25Z</dc:date>
    <item>
      <title>create multiple macro vars based on data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902270#M356549</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to create multiple macro variables based on data set that contain 2 colums:&lt;/P&gt;
&lt;P&gt;column 1 is Macro var name&lt;/P&gt;
&lt;P&gt;Column 2 is the value that the macro var will get&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;Macro var M0 will get value 2309&lt;/P&gt;
&lt;P&gt;Macro var M1 will get value 2308&lt;/P&gt;
&lt;P&gt;and so on&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;I think that I did it well but when I write&amp;nbsp;%put &amp;amp;&amp;amp;m&amp;amp;n..;&amp;nbsp; to see the last macro var then I get&amp;nbsp; warning and cannot see its value.Why???&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference M not resolved.&lt;BR /&gt;26 %put &amp;amp;&amp;amp;m&amp;amp;n..;&lt;BR /&gt;&amp;amp;m..&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startMon=2012;
%let LastMon=2309;

data _null_;
date_start=mdy(mod(&amp;amp;startMon,100),1,floor(&amp;amp;startMon/100));
date_end=mdy(mod(&amp;amp;LastMon,100),1,floor(&amp;amp;LastMon/100));
n = intck('month',date_start,date_end);
call symputx('n',put(counter,best.));
call symputx('date_start',put(date_start,best.));
call symputx('date_end',put(date_end,best.));
format date_start date_end  date9.;
run;


data want_month;
date=&amp;amp;date_start.;
end_date=&amp;amp;date_end.;
YYMM=input(put(date,yymmn4.),best.);
format date end_date date9.;
do while (date&amp;lt;=end_date);
output;
date=intnx('month', date, 1, 's');
YYMM=input(put(date,yymmn4.),best.);
end;
format date YYMMN4.;
drop date end_date;
run;

proc sort data=want_month;
by descending YYMM ;
Run;

DATA want_month2(DROP=seq);
SET want_month;
seq = _N_-1; 
Macro_Var_Name=CATS("M",seq); 
RUN;


data _null_;
set want_month2;
call symputx(Macro_Var_Name,YYMM);
run;
%put &amp;amp;M0;
%put &amp;amp;M1;
%put &amp;amp;M33;
%put &amp;amp;&amp;amp;m&amp;amp;n..;/******Why WARNING: Apparent symbolic reference M not resolved??????***/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Nov 2023 06:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902270#M356549</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-11-09T06:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple macro vars based on data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902277#M356552</link>
      <description>&lt;P&gt;Remove the double dots after the macro variable reference.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 07:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902277#M356552</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-09T07:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple macro vars based on data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902280#M356553</link>
      <description>&lt;P&gt;%put &amp;amp;&amp;amp;m&amp;amp;n; doesn't work because your macro variable &amp;amp;n doesn't contain a number but a fullstop (="missing").&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1699515813242.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89576i6AC96124888C5063/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1699515813242.png" alt="Patrick_0-1699515813242.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you look at your first data step you'll see why that happens&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1699515876582.png" style="width: 617px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89577i161449DF0B22212A/image-dimensions/617x199?v=v2" width="617" height="199" role="button" title="Patrick_1-1699515876582.png" alt="Patrick_1-1699515876582.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I guess what you intended to do but then missed during development was to use variable N instead of COUNTER to populate macro variable &amp;amp;n&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1699516032230.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89578i7C99DD2D21DD3D83/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_2-1699516032230.png" alt="Patrick_2-1699516032230.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 07:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902280#M356553</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-09T07:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple macro vars based on data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902284#M356556</link>
      <description>&lt;P&gt;If I were you I would use MacroArray package and do it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generate data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* input data */

%let startMon=2012;
%let LastMon=2309;

data have;
  n=-1;
  do yymm=&amp;amp;startMon. to &amp;amp;LastMon.;
    if input(put(yymm,z4.)!!"01",?? yymmdd6.) then
        output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Create macro array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
%helpPackage(macroArray,'%array()')
*/

/* create macro array M from variable yymm */
%array(ds=have, vars=yymm#M, macarray=Y)

/* loop over array M with do_over... */
%put %do_over(M);


/* ...or loop by yourself */
%macro loop();
  %do i= &amp;amp;mLbound. %to &amp;amp;mHbound.;
    %put %M(&amp;amp;i.); /* &amp;lt;- %M() is a macro array, so you don't have to fight with &amp;amp;&amp;amp; */
  %end;
%mend;
%loop()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. Here are some instructions how to get macroArray package and where the documentation is.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Details about SAS Packages Framework:
- https://github.com/yabwon/SAS_PACKAGES

Tutorial:
- https://github.com/yabwon/HoW-SASPackages

MacroArray documentation:
- https://github.com/SASPAC/macroarray/blob/main/macroarray.md
*/


/* Install SAS Packages Framework and macroaArray package. */
/* Run this only once. */
filename SPFinit url "https://bit.ly/SPFinit";
%include SPFinit; 
filename SPFinit clear;

filename packages "&amp;lt;directory/for/packages/&amp;gt;"; 
%installPackage(SPFinit macroArray)




/* Run this in your SAS Serrion (or add it to autoexec). */
/* Enable framework and load package  */
filename packages "&amp;lt;directory/for/packages/&amp;gt;";
%include packages(SPFinit.sas); 
%loadPackage(macroArray)&lt;BR /&gt;&lt;BR /&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 08:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-macro-vars-based-on-data-set/m-p/902284#M356556</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-11-09T08:48:51Z</dc:date>
    </item>
  </channel>
</rss>

