<?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: Assign and Retain Values to Dynamic Variable inside a macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322302#M62001</link>
    <description>&lt;P&gt;Running SAS on WRDS - it says the follwing: looks like i might have it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;---SAS/ETS&lt;BR /&gt;31JUL2019&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2017 02:38:05 GMT</pubDate>
    <dc:creator>Mila</dc:creator>
    <dc:date>2017-01-04T02:38:05Z</dc:date>
    <item>
      <title>Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322299#M61999</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro to dynamically compute cumulative returns across variables in my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue: the macro below is overwriting the results obtained for the prior variable instead of creating separate columns in each iteration.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attempted solutions:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Tried to assign names to&amp;nbsp;%LET colname = &amp;amp;field; and later assigning it by:&amp;nbsp;&amp;amp;colname =(EXP(cum_ln_return)-1); this doesnt work&lt;/P&gt;&lt;P&gt;2) do i need to use symput, no idea how to start here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is my code so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro cumrets (field=);&amp;nbsp;&lt;BR /&gt;%LET colname = "&amp;amp;field";&amp;nbsp;&lt;SPAN&gt;/****** this line of code is an error - need variables to be dynamic - see below **********/&lt;/SPAN&gt;&lt;BR /&gt;%LET var = &amp;amp;field;&lt;BR /&gt;data project.ToyData6;&lt;BR /&gt;set project.ToyData3;&lt;BR /&gt;by i;&lt;BR /&gt;ln_return = LOG(1+(&amp;amp;var));&lt;BR /&gt;if first.i then cum_ln_return = ln_return;&lt;BR /&gt;else cum_ln_return + ln_return;&lt;BR /&gt;&amp;amp;colname =(EXP(cum_ln_return)-1); /****** this line of code is an error - need variables to be dynamic, if i were to put a constant variable here like ColName code runs fine, but i only get to see results for last variable &lt;SPAN&gt;TotalReportableGrowth_lag7&lt;/SPAN&gt;&amp;nbsp; **********/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend cumrets;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro loop(values);&lt;BR /&gt;%let count=%sysfunc(countw(&amp;amp;values));&lt;BR /&gt;%do i = 1 %to &amp;amp;count;&lt;BR /&gt;%let value=%qscan(&amp;amp;values,&amp;amp;i,%str(,));&lt;BR /&gt;%cumrets (field=&amp;amp;value);&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%loop(%str(ret,&lt;BR /&gt;CLongGrowth_lag6,&lt;BR /&gt;CLongGrowth_lag7,&lt;BR /&gt;TotalReportableGrowth_lag1,&lt;BR /&gt;TotalReportableGrowth_lag2,&lt;BR /&gt;TotalReportableGrowth_lag3,&lt;BR /&gt;TotalReportableGrowth_lag4,&lt;BR /&gt;TotalReportableGrowth_lag5,&lt;BR /&gt;TotalReportableGrowth_lag6,&lt;BR /&gt;TotalReportableGrowth_lag7));&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 02:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322299#M61999</guid>
      <dc:creator>Mila</dc:creator>
      <dc:date>2017-01-04T02:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322301#M62000</link>
      <description>&lt;P&gt;Do you have SAS ETS?&lt;/P&gt;
&lt;P&gt;You can check by running the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc setinit;run;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 02:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322301#M62000</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-04T02:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322302#M62001</link>
      <description>&lt;P&gt;Running SAS on WRDS - it says the follwing: looks like i might have it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;---SAS/ETS&lt;BR /&gt;31JUL2019&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 02:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322302#M62001</guid>
      <dc:creator>Mila</dc:creator>
      <dc:date>2017-01-04T02:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322310#M62003</link>
      <description>&lt;P&gt;This is much more likely to be solved using arrays than using macro language. &amp;nbsp;A little bit of macro language might be involved in order to permit different sets of variables to be processed. &amp;nbsp;But mostly, the intent is to process a set of variables with the same logic. &amp;nbsp;That screams for the use of arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First. a few questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Do you really have a variable named "i" that was used to sort your data set?&lt;/LI&gt;
&lt;LI&gt;Of all the variables you are computing (logs, returns, cumulative values), which ones do you actually want to keep in the final data set? &amp;nbsp;Which can be dropped after being used for computations?&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 04 Jan 2017 03:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322310#M62003</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-04T03:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322313#M62004</link>
      <description>&lt;P&gt;Hey Reeza/Astounding,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the fuller code is attached and dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To keep:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Commomatch, yearbis, week3, ret, i, and&amp;nbsp;last column would be the cumulative returns of each of the variables stated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 03:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322313#M62004</guid>
      <dc:creator>Mila</dc:creator>
      <dc:date>2017-01-04T03:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322317#M62005</link>
      <description>&lt;P&gt;If I understand what you are saying about which variables to keep, this would fit the bill for two variables. &amp;nbsp;Taking out the macro language for a moment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data project.ToyData6;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set project.ToyData3;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;by i;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;array varlist {2} ret CLongGrowth_lag6;&lt;/P&gt;
&lt;P&gt;array cumvals {2} _temporary_;&lt;/P&gt;
&lt;P&gt;array logvals {2} _temporary_;&lt;/P&gt;
&lt;P&gt;array returns {2} rtn_ret rtn_CLongGrowth_lag6;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;logvals{_n_} = log(1+varlist{_n_});&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if first.i then cumvals{_n_} = logvals{_n_};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else cumvals{_n_} = cumvals{_n_} + logvals{_n_};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;returns{_n_} = exp(cumvals{_n_}) - 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eventually, macro language will make its way into the picture. &amp;nbsp;But to start, see if this is doing what you would hope when you process two variables instead of one.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 03:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322317#M62005</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-04T03:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322325#M62006</link>
      <description>&lt;P&gt;This line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;returns{_n_} = exp(cumvals{_n_}) - 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;seems to be returning the following error - not sure that i understand why...google seems to be a little vague:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: Invalid macro parameter name {. It should be a valid SAS identifier no longer than 32 characters.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 04:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322325#M62006</guid>
      <dc:creator>Mila</dc:creator>
      <dc:date>2017-01-04T04:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322327#M62007</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/121713"&gt;@Mila&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Running SAS on WRDS - it says the follwing: looks like i might have it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;---SAS/ETS&lt;BR /&gt;31JUL2019&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider looking&amp;nbsp;into PROC EXPAND as an alternative&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/faq/creating_tiimeseries_variables_proc_expand.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/faq/creating_tiimeseries_variables_proc_expand.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 04:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322327#M62007</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-04T04:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322376#M62011</link>
      <description>&lt;P&gt;That message is a bit strange, since there is no macro language involved. &amp;nbsp;Is it possible to post the log?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 11:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322376#M62011</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-04T11:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322424#M62014</link>
      <description>&lt;P&gt;Very odd- it works perfectly now without the macros- &amp;nbsp;thank you. Nice to see arrays in action in sas.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any chance i can nest it in a macro like below? Syntax has gotten the best of me - below code is erorring out (i hvae 115 of those variables in the actual dataset, would be nice to have it automated for the "returns" array - tried the %DO_OVER macro but didnt work)....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro cumretsarr (field=,cnt=);&lt;BR /&gt;%LET var = &amp;amp;field;&lt;BR /&gt;data project.ToyData6;&lt;BR /&gt;set project.ToyData3;&lt;/P&gt;&lt;P&gt;data project.ToyData6;&lt;BR /&gt;set project.ToyData3;&lt;BR /&gt;by i;&lt;BR /&gt;array varlist {cnt} &amp;amp;var;&lt;BR /&gt;array cumvals {cnt} _temporary_;&lt;BR /&gt;array logvals {cnt} _temporary_;&lt;BR /&gt;array returns {cnt} &amp;amp;var&lt;BR /&gt;/* array returns {cnt} %DO_OVER(var,PHRASE=rtn.? ) ; ******/&lt;BR /&gt;do _n_=1 to cnt;&lt;BR /&gt;logvals{_n_} = log(1+varlist{_n_});&lt;BR /&gt;if first.i then cumvals{_n_} = logvals{_n_};&lt;BR /&gt;else cumvals{_n_} = cumvals{_n_} + logvals{_n_};&lt;BR /&gt;returns{_n_} = exp(cumvals{_n_}) - 1;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend cumretsarr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro loop(values);&lt;BR /&gt;%let count=%sysfunc(countw(&amp;amp;values));&lt;BR /&gt;%do i = 1 %to &amp;amp;count;&lt;BR /&gt;%let value=%qscan(&amp;amp;values,&amp;amp;i,%str(,));&lt;BR /&gt;/* %cumrets (field=&amp;amp;value,cnt=count); */&lt;BR /&gt;%cumretsarr (field=&amp;amp;value,cnt=count);&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%loop(%str(ret,&lt;BR /&gt;CLongGrowth_lag6,&lt;BR /&gt;CLongGrowth_lag7,&lt;BR /&gt;TotalReportableGrowth_lag1,&lt;BR /&gt;TotalReportableGrowth_lag2,&lt;BR /&gt;TotalReportableGrowth_lag3,&lt;BR /&gt;TotalReportableGrowth_lag4,&lt;BR /&gt;TotalReportableGrowth_lag5,&lt;BR /&gt;TotalReportableGrowth_lag6,&lt;BR /&gt;TotalReportableGrowth_lag7));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/************ below is part of the log file when above is run - doesnt seem to like the list &amp;amp;var and the %do_over macro i tried to invoke ******************/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NOTE: Line generated by the invoked macro "CUMRETSARR".&lt;BR /&gt;1031 data project.ToyData6; set&lt;BR /&gt;1031! project.ToyData3; by i; array varlist {cnt} &amp;amp;var; array cumvals {cnt} _temporary_; array&lt;BR /&gt;--- ---&lt;BR /&gt;---&lt;BR /&gt;22 22&lt;BR /&gt;22&lt;BR /&gt;202 202&lt;BR /&gt;202&lt;BR /&gt;1031! logvals {cnt} _temporary_; array returns {cnt} &amp;amp;var do _n_=1 to cnt; logvals{_n_}&lt;BR /&gt;NOTE 137-205: Line generated by the invoked macro "CUMRETSARR".&lt;BR /&gt;1031 data project.ToyData6; set project.ToyData3; data project.ToyData6; set&lt;BR /&gt;1031! project.ToyData3; by i; array varlist {cnt} &amp;amp;var; array cumvals {cnt} _temporary_; array&lt;BR /&gt;1031! logvals {cnt} _temporary_; array returns {cnt} &amp;amp;var do _n_=1 to cnt; logvals{_n_}&lt;BR /&gt;---&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *.&lt;/P&gt;&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "CUMRETSARR".&lt;BR /&gt;1031 data project.ToyData6; set project.ToyData3; data project.ToyData6; set&lt;BR /&gt;1031! project.ToyData3; by i; array varlist {cnt} &amp;amp;var; array cumvals {cnt} _temporary_; array&lt;BR /&gt;1031! logvals {cnt} _temporary_; array returns {cnt} &amp;amp;var do _n_=1 to cnt; logvals{_n_}&lt;BR /&gt;---&lt;BR /&gt;202&lt;BR /&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;NOTE 137-205: Line generated by the invoked macro "CUMRETSARR".&lt;BR /&gt;1031 data project.ToyData6; set project.ToyData3; data project.ToyData6; set&lt;BR /&gt;1031! project.ToyData3; by i; array varlist {cnt} &amp;amp;var; array cumvals {cnt} _temporary_; array&lt;BR /&gt;1031! logvals {cnt} _temporary_; array returns {cnt} &amp;amp;var do _n_=1 to cnt; logvals{_n_}&lt;BR /&gt;-&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 15:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322424#M62014</guid>
      <dc:creator>Mila</dc:creator>
      <dc:date>2017-01-04T15:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322431#M62017</link>
      <description>&lt;P&gt;To convert this to macros, you would not need to loop.&amp;nbsp; (In fact, this sort of looping is a hidden drawback to macro language.&amp;nbsp; Without looping, you need 1 DATA step.&amp;nbsp; With looping, you need 1 DATA step for each variable being processed.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, the parameters to the macro would change.&amp;nbsp; You would need to specify the entire list of incoming variables, and the entire list of variables to hold the return values.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro cumretarr (field_list_in=, field_list_out=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When calling the macro, it would look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%cumretsarr (field_list_in=ret CLongGrowth_lag6 CLongGrowth_lag7 TotalReportableGrowth_lag1 TotalReportableGrowth_lag2 ... TotalReportableGrowth_lag7, field_list_out=return_ret return_CLG_lag6 return_CLG_lag7 return_TRG_lag1 ... return_TRG_lag7)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need to decide on the names to use to hold results for each incoming variable.&amp;nbsp; (But you would need to do that anyway, even if you try to loop through one variable at a time.)&amp;nbsp; Macro language can count how many elements are in each list, and can construct appropriate ARRAY statements.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cnt = %sysfunc(countw(&amp;amp;field_list_in));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array varlist {&amp;amp;cnt} &amp;amp;field_list_in;&lt;/P&gt;
&lt;P&gt;array returns {&amp;amp;cnt} &amp;amp;field_list_out;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then refer to &amp;amp;CNT elsewhere as needed ... the other ARRAY statements, as well as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do _n_=1 to &amp;amp;CNT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 15:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322431#M62017</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-04T15:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Assign and Retain Values to Dynamic Variable inside a macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322589#M62030</link>
      <description>&lt;P&gt;Thank you this was tremendously helpful! Much appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 05:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Assign-and-Retain-Values-to-Dynamic-Variable-inside-a-macro/m-p/322589#M62030</guid>
      <dc:creator>Mila</dc:creator>
      <dc:date>2017-01-05T05:46:14Z</dc:date>
    </item>
  </channel>
</rss>

