<?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: Run macro from macro var components in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954465#M372766</link>
    <description>Please show what you are calculating; I‘m quite sure the whole calculation could be done in a single step, with (almost) no macro coding.</description>
    <pubDate>Mon, 23 Dec 2024 07:50:58 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-12-23T07:50:58Z</dc:date>
    <item>
      <title>Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954442#M372750</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a macro called RRR&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro RRR(V_months);
code here
%mend RRR; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Usually I run the macro by typing the months as you see here&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%RRR_STEP1(V_months=2211+2210+2209+2208+2207+2206)
%RRR_STEP1(V_months=2210+2209+2208+2207+2206+2205)
%RRR_STEP1(V_months=2209+2208+2207+2206+2205+2204)
%RRR_STEP1(V_months=2208+2207+2206+2205+2204+2203)
%RRR_STEP1(V_months=2207+2206+2205+2204+2203+2202)
%RRR_STEP1(V_months=2206+2205+2204+2203+2202+2201)
%RRR_STEP1(V_months=2205+2204+2203+2202+2201+2112)
%RRR_STEP1(V_months=2204+2203+2202+2201+2112+2111)
%RRR_STEP1(V_months=2203+2202+2201+2112+2111+2110)
%RRR_STEP1(V_months=2202+2201+2112+2111+2110+2109)
%RRR_STEP1(V_months=2201+2112+2111+2110+2109+2108)
%RRR_STEP1(V_months=2112+2111+2110+2109+2108+2107)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it is not so comfortable to type so many dates manually.&lt;/P&gt;
&lt;P&gt;Let's say that there is a macro var called&amp;nbsp;Vector_CAT that automatically calculate the macro dates that need to run.&lt;/P&gt;
&lt;P&gt;In this case this macro var get value : 2306+2305+2304+2303+2302+2301,2307+2306+2305+2304+2303+2302,2308+2307+2306+2305+2304+2303,2309+2308+2307+2306+2305+2304,2310+2309+23&lt;BR /&gt;08+2307+2306+2305&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to run the macro multiple times&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try this code but I am not sure it is correct.&lt;/P&gt;
&lt;P&gt;What do you think?&lt;/P&gt;
&lt;P&gt;is it correct?&lt;/P&gt;
&lt;P&gt;Why&amp;nbsp; should I write the delimiter (comma)&amp;nbsp; like this :&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;%str(,) &amp;nbsp;&amp;nbsp;&amp;nbsp;?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Is&amp;nbsp;there&amp;nbsp;another&amp;nbsp;good&amp;nbsp;way&amp;nbsp;to&amp;nbsp;run&amp;nbsp;the&amp;nbsp;macro&amp;nbsp;automatically&amp;nbsp;from&amp;nbsp;the&amp;nbsp;macro&amp;nbsp;varaible&amp;nbsp;components?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro run_step1;
%do i=1 %to &amp;amp;n_run_step1;
%let mm = %scan(%quote(&amp;amp;Vector_CAT), &amp;amp;i, %str(,)); 
%RRR_STEP1(&amp;amp;mm);
%end;
%mend run_step1;
%run_step1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2024 15:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954442#M372750</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-12-22T15:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954443#M372751</link>
      <description>&lt;P&gt;We have already shown you how to loop over months, &lt;A href="https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951717#M372005" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/calculate-macro-variables-in-structure-YYMM/m-p/951717#M372005&lt;/A&gt;. Which makes me wonder why you didn't try that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This looks like you want a moving average (or moving sum) of six months. If so, then you don't want macros at all, you want PROC EXPAND.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/iml/2016/01/27/moving-average-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Of course, you don't explain anything, you just jump into the code without explanation. So, please explain the purpose of this macro, without reference to code. Don't make us guess. Don't waste our time by making us figure out what you really are doing, when you already know what you really are doing and could tell us.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2024 16:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954443#M372751</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-22T16:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954449#M372754</link>
      <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;. It is much easier to tell us what you are getting at with your analysis. That will provide much better solutions to your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But apart from that ... if you want to go forward through a comma-separated list (which is the value of a macro variable), I would do it the way below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET Vector_CAT=2306+2305+2304+2303+2302+2301,2307+2306+2305+2304+2303+2302,2308+2307+2306+2305+2304+2303;

data _NULL_;
 file log;
 i=1;
 do while ( scan("&amp;amp;Vector_CAT",i,",") ne " " );
  currpart=trim(left(upcase(scan("&amp;amp;Vector_CAT",i,","))));
  put currpart;
  i=i+1;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2024 17:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954449#M372754</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-12-22T17:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954452#M372755</link>
      <description>&lt;P&gt;So assuming that by your use of the word MONTH in your question we can leap to the conclusion that the four digit strings in your + delimited strings refer to dates as 4 digit strings where the digits represent the two least significant digits of the year and the two digits of the month within that year we can just use couple of nest %DO loops.&amp;nbsp; To use %DO loops we will need to define a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's also assume you want to use the same 4 digit strings as input to the new macro.&amp;nbsp; So the first step should be to convert them into actual DATE values so they can be used with SAS functions that understand dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each execution of the outer loop will generate one call to the existing macro.&amp;nbsp; The inner loop will be used to generate the + delimited string to pass to the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xyz(start,stop);
%local n step i j list;
%let start=%sysfunc(inputn(&amp;amp;start.01,yymmdd6.));
%let stop=%sysfunc(inputn(&amp;amp;stop.01,yymmdd6.));
%let n=%sysfunc(intck(month,&amp;amp;start,&amp;amp;stop));
%let step=%sysfunc(sign(&amp;amp;n));
%do i=0 %to &amp;amp;n %by &amp;amp;step;
  %let list=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;i),yymmn4.);
  %do j=1 %to 5;
    %let list=&amp;amp;list+%sysfunc(intnx(month,&amp;amp;start,&amp;amp;i-&amp;amp;j),yymmn4.);
  %end;
  %RRR_STEP1(V_months=&amp;amp;list);
%end;
%mend xyz;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which for your example you would call with these inputs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%xyz(2211,2112);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since we don't have your RRR_STEP1 macro let's replace the macro call with a %PUT&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put RRR_STEP1(V_months=&amp;amp;list);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so we can run it and see if it is generating the desired macro call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;133  %xyz(2211,2112);
RRR_STEP1(V_months=2211+2210+2209+2208+2207+2206)
RRR_STEP1(V_months=2210+2209+2208+2207+2206+2205)
RRR_STEP1(V_months=2209+2208+2207+2206+2205+2204)
RRR_STEP1(V_months=2208+2207+2206+2205+2204+2203)
RRR_STEP1(V_months=2207+2206+2205+2204+2203+2202)
RRR_STEP1(V_months=2206+2205+2204+2203+2202+2201)
RRR_STEP1(V_months=2205+2204+2203+2202+2201+2112)
RRR_STEP1(V_months=2204+2203+2202+2201+2112+2111)
RRR_STEP1(V_months=2203+2202+2201+2112+2111+2110)
RRR_STEP1(V_months=2202+2201+2112+2111+2110+2109)
RRR_STEP1(V_months=2201+2112+2111+2110+2109+2108)
RRR_STEP1(V_months=2112+2111+2110+2109+2108+2107)

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 14:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954452#M372755</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-23T14:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954463#M372765</link>
      <description>For each set ( for example 2211 2210 2209 2208 2207 2206) need to calculate for each argument average 6 months back so for 2211 calculate average of 2211-2206 and for 2210 calculate average of 2210-2205 and so on. Please note yymm structure.</description>
      <pubDate>Mon, 23 Dec 2024 06:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954463#M372765</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-12-23T06:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954465#M372766</link>
      <description>Please show what you are calculating; I‘m quite sure the whole calculation could be done in a single step, with (almost) no macro coding.</description>
      <pubDate>Mon, 23 Dec 2024 07:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954465#M372766</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-23T07:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954469#M372768</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* "MOVAVE n" = Backward moving average of n neighboring values */
proc expand data=sashelp.pricedata(drop=price1--price17 discount) out=want;
 by Region Line Product;
 id date;
 convert sale  = sale_movave  / transformout=(movave 6);
 convert price = price_movave / transformout=(movave 6);
 convert cost  = cost_movave  / transformout=(movave 6);
run;
QUIT;

/* If you need more control on what exactly is happening in the */
/* transformation operation, you can use PROC TIMEDATA          */
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need SAS/ETS or SAS Econometrics for the above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ciao, Koen&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 09:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954469#M372768</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-12-23T09:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro from macro var components</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954477#M372771</link>
      <description>&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;For each set ( for example 2211 2210 2209 2208 2207 2206) need to calculate for each argument average 6 months back so for 2211 calculate average of 2211-2206 and for 2210 calculate average of 2210-2205 and so on. Please note yymm structure.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a moving average. As I said, you want to do this in PROC EXPAND. SAS has already programmed this for you. No need for macros. In fact, before you start coding some statistical calculation via macros, you really should check to see if SAS has a PROC that will do this. And if you don't know or can't find one, you can simply ask here in these forums if there is a SAS PROC that does the statistical calculation you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: You want to calculate the moving average for &lt;FONT color="#FF0000"&gt;variables&lt;/FONT&gt; that contain some sort of monthly average. But you don't show variables, you show &lt;FONT color="#FF0000"&gt;NUMBERs&lt;/FONT&gt; in your problem description. These are numbers because they are not valid variable names. Please make the data or variable names clear from now on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So back to my other point. Please tell us what you are doing, and why you are doing it, instead of just focusing on code. And please don't make us ask for this critical information repeatedly.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 11:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-from-macro-var-components/m-p/954477#M372771</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-23T11:01:00Z</dc:date>
    </item>
  </channel>
</rss>

