<?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: calculate macro variables in structure YYMM in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951717#M372005</link>
    <description>&lt;P&gt;Other way then this way?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=2211;/***חודש עבורו מחושבת הכנסה פנויה***/

data temp(DROP= YYMM  date_YYMM);
YYMM="&amp;amp;month.";
date_YYMM=mdy(mod(YYMM,100),1,floor(YYMM/100));
mon12="&amp;amp;step2_mon12.";
mon11=put(intnx('Month',date_YYMM,-1,'s'),yymmn4.);
mon10=put(intnx('Month',date_YYMM,-2,'s'),yymmn4.);
mon9=put(intnx('Month',date_YYMM,-3,'s'),yymmn4.);
mon8=put(intnx('Month',date_YYMM,-4,'s'),yymmn4.);
mon7=put(intnx('Month',date_YYMM,-5,'s'),yymmn4.);
mon6=put(intnx('Month',date_YYMM,-6,'s'),yymmn4.);
mon5=put(intnx('Month',date_YYMM,-7,'s'),yymmn4.);
mon4=put(intnx('Month',date_YYMM,-8,'s'),yymmn4.);
mon3=put(intnx('Month',date_YYMM,-9,'s'),yymmn4.);
mon2=put(intnx('Month',date_YYMM,-10,'s'),yymmn4.);
mon1=put(intnx('Month',date_YYMM,-11,'s'),yymmn4.);
call symputx('mon12',mon12);
call symputx('mon11',mon11);
call symputx('mon10',mon10);
call symputx('mon9',mon9);
call symputx('mon8',mon8);
call symputx('mon7',mon7);
call symputx('mon6',mon6);
call symputx('mon5',mon5);
call symputx('mon4',mon4);
call symputx('mon3',mon3);
call symputx('mon2',mon2);
call symputx('mon1',mon1);
Run;
%put mon12=&amp;amp;mon12;
%put mon11=&amp;amp;mon11;
%put mon10=&amp;amp;mon10;
%put mon9=&amp;amp;mon9;
%put mon8=&amp;amp;mon8;
%put mon7=&amp;amp;mon7;
%put mon6=&amp;amp;mon6;
%put mon5=&amp;amp;mon5;
%put mon4=&amp;amp;mon4;
%put mon3=&amp;amp;mon3;
%put mon2=&amp;amp;mon2;
%put mon2=&amp;amp;mon1;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 24 Nov 2024 11:13:26 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2024-11-24T11:13:26Z</dc:date>
    <item>
      <title>calculate macro variables in structure YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951716#M372004</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Lets say that user define in macro variable mon12 as&amp;nbsp; 2211 (In structure YYMM)&lt;/P&gt;
&lt;P&gt;%let mon12=2211;&lt;/P&gt;
&lt;P&gt;My question-&lt;/P&gt;
&lt;P&gt;What is the way to calculate the other macro varaibles&lt;/P&gt;
&lt;P&gt;mon11&lt;BR /&gt;mon10&lt;BR /&gt;mon9&lt;BR /&gt;mon8&lt;BR /&gt;mon7&lt;BR /&gt;mon6&lt;BR /&gt;mon5&lt;BR /&gt;mon4&lt;BR /&gt;mon3&lt;BR /&gt;mon2&lt;BR /&gt;mon1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mon12=2211;

%let mon11=2210;
%let mon10=2209;
%let mon9=2208;
%let mon8=2207;
%let mon7=2206;
%let mon6=2205;
%let mon5=2204;
%let mon4=2203;
%let mon3=2202;
%let mon2=2201;
%let mon1=2112;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2024 11:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951716#M372004</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-11-24T11:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: calculate macro variables in structure YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951717#M372005</link>
      <description>&lt;P&gt;Other way then this way?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=2211;/***חודש עבורו מחושבת הכנסה פנויה***/

data temp(DROP= YYMM  date_YYMM);
YYMM="&amp;amp;month.";
date_YYMM=mdy(mod(YYMM,100),1,floor(YYMM/100));
mon12="&amp;amp;step2_mon12.";
mon11=put(intnx('Month',date_YYMM,-1,'s'),yymmn4.);
mon10=put(intnx('Month',date_YYMM,-2,'s'),yymmn4.);
mon9=put(intnx('Month',date_YYMM,-3,'s'),yymmn4.);
mon8=put(intnx('Month',date_YYMM,-4,'s'),yymmn4.);
mon7=put(intnx('Month',date_YYMM,-5,'s'),yymmn4.);
mon6=put(intnx('Month',date_YYMM,-6,'s'),yymmn4.);
mon5=put(intnx('Month',date_YYMM,-7,'s'),yymmn4.);
mon4=put(intnx('Month',date_YYMM,-8,'s'),yymmn4.);
mon3=put(intnx('Month',date_YYMM,-9,'s'),yymmn4.);
mon2=put(intnx('Month',date_YYMM,-10,'s'),yymmn4.);
mon1=put(intnx('Month',date_YYMM,-11,'s'),yymmn4.);
call symputx('mon12',mon12);
call symputx('mon11',mon11);
call symputx('mon10',mon10);
call symputx('mon9',mon9);
call symputx('mon8',mon8);
call symputx('mon7',mon7);
call symputx('mon6',mon6);
call symputx('mon5',mon5);
call symputx('mon4',mon4);
call symputx('mon3',mon3);
call symputx('mon2',mon2);
call symputx('mon1',mon1);
Run;
%put mon12=&amp;amp;mon12;
%put mon11=&amp;amp;mon11;
%put mon10=&amp;amp;mon10;
%put mon9=&amp;amp;mon9;
%put mon8=&amp;amp;mon8;
%put mon7=&amp;amp;mon7;
%put mon6=&amp;amp;mon6;
%put mon5=&amp;amp;mon5;
%put mon4=&amp;amp;mon4;
%put mon3=&amp;amp;mon3;
%put mon2=&amp;amp;mon2;
%put mon2=&amp;amp;mon1;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Nov 2024 11:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951717#M372005</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-11-24T11:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: calculate macro variables in structure YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951718#M372006</link>
      <description>&lt;P&gt;You could use a DO loop in a DATA step, or a %DO loop inside a macro.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2024 11:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951718#M372006</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-24T11:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: calculate macro variables in structure YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951721#M372008</link>
      <description>&lt;P&gt;Why would you need so many macro variables?&amp;nbsp; Couldn't you just calculate the string you want based on the starting date and the month offset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway inside a macro (so you can use %DO loop) you could run code like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First convert your MON12 macro variable with the YYMM string into a baseline date value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date0=%sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;mon12,yymmn.)),-12));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use a %DO loop to generate the other 11 macro variables from that base date.&amp;nbsp; Make sure to make them GLOBAL if you need to use them after the macro ends.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do offset=1 %to 11;
  %if not %symexist(mon&amp;amp;offset) %then %global mon&amp;amp;offset;
  %let mon&amp;amp;offset=%sysfunc(intnx(month,&amp;amp;date0,&amp;amp;offset),yymmn4.);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2024 13:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951721#M372008</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-24T13:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: calculate macro variables in structure YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951726#M372010</link>
      <description>&lt;P&gt;How about start using the &lt;STRONG&gt;&lt;A href="https://github.com/SASPAC/macroarray" target="_self"&gt;macroArray&lt;/A&gt;&lt;/STRONG&gt; package:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Documentation&lt;/EM&gt; is &lt;STRONG&gt;&lt;A href="https://github.com/SASPAC/macroarray/blob/main/macroarray.md" target="_self"&gt;here&lt;/A&gt;&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Article&lt;/STRONG&gt; describing the package is here from &lt;STRONG&gt;&lt;A href="https://github.com/SASPAC/macroarray/tree/main/extras" target="_self"&gt;PharmaSUG&lt;/A&gt;&lt;/STRONG&gt;&amp;nbsp;(and &lt;STRONG&gt;&lt;A href="https://www.lexjansen.com/pharmasug/2024/AP/PharmaSUG-2024-AP-108.pdf" target="_self"&gt;here&lt;/A&gt;&lt;/STRONG&gt;) and &lt;STRONG&gt;&lt;A href="https://www.wuss.org/proceedings/2024/124/124_FINAL_paper_pdf.pdf" target="_self"&gt;WUSS&lt;/A&gt;&lt;/STRONG&gt; conferences.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%loadPackage(macroArray)
/*
%helpPackage(macroArray,'%array()')
*/
resetline;

/* create */
%array(mon[12] $ 4, function=put(intnx('month','1dec2021'd,_I_-1,"S"),yymmdd4.), macarray=Y)


/* use */
%put %do_over(mon);

%put %mon(1), %mon(2) ... %mon(12);


/* delete */
%deleteMacArray(mon, macarray=Y)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1
2    /* create */
3    %array(mon[12] $ 4, function=put(intnx('month','1dec2021'd,_I_-1,"S"),yymmdd4.), macarray=Y)
NOTE:[ARRAY] 12 macrovariables created
4
5
6    /* use */
7    %put %do_over(mon);
2112 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211
8
9    %put %mon(1), %mon(2) ... %mon(12);
2112, 2201 ... 2211
10
11
12   /* delete */
13   %deleteMacArray(mon, macarray=Y)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2024 16:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951726#M372010</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-11-24T16:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: calculate macro variables in structure YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951728#M372012</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Loops.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Loops.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Loops.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Did I say "Loops!" already? Still, I'll say it again: &lt;STRONG&gt;"LOOPS!!!"&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=2211;

data temp;
date = input("&amp;amp;month.",yymmn4.);
format date yymmn6.;
do i = 12 to 1 by -1;
  date_yymm = put(date,yymmn4.);
  call symputx(cats("mon",i),date_yymm);
  output;
  date = intnx("month",date,-1);
end;
drop i;
run;

%macro show;
%do i = 12 %to 1 %by -1;
  %put mon&amp;amp;i=&amp;amp;&amp;amp;mon&amp;amp;i.;
%end;
%mend;
%show&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Whenever you see something repetitive, think "loop!".&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2024 18:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951728#M372012</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-24T18:37:07Z</dc:date>
    </item>
  </channel>
</rss>

