<?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: How do i modify all elements of a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738043#M230153</link>
    <description>&lt;P&gt;Like this?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro corr ( data      = d1
&amp;nbsp; &amp;nbsp;         , item_list = item1 item2 item3 item4
&amp;nbsp; &amp;nbsp;         , tmpt      = T1
            , ref_list  = ref1 ref2 ref3 ref4      );&amp;nbsp;

  %local i with item;

  %do i=1 %to %sysfunc(countw(&amp;amp;ref_list));
    %let with=&amp;amp;with %scan(&amp;amp;ref_list, &amp;amp;i)_&amp;amp;tmpt.;
  %end;

  %do i=1 %to %sysfunc(countw(&amp;amp;item_list));
    %let item=%scan(&amp;amp;item_list, &amp;amp;i);
    proc corr data=&amp;amp;data. spearman;
      var &amp;amp;item._&amp;amp;tmpt.;
      with &amp;amp;with. ;
    run;
  %end;&lt;BR /&gt;
%mend;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Apr 2021 22:24:00 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-04-29T22:24:00Z</dc:date>
    <item>
      <title>How do i modify all elements of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738035#M230150</link>
      <description>&lt;P&gt;I'm working on a macro that calculates cross-sectional correlations for any number of "target" variables at a given timepoint, all correlated with the same reference variables. I had the macro working with hard coded references variables listed out in the WITH statement and then having the macro loop append Timepoint, but I would like to be able to provide just the list of ref vars in the macro&amp;nbsp;call (e.g.,&amp;nbsp; ref_list = ref1 ref2 ref3 ref4) and have the macro append the timepoint on to each ref var name for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So a macro call for %macro corr (data=d1, item_list = item1 item2 item3 item4, tmpt = T1, ref_list = ref1 ref2 ref3 ref4); would produce the below code for the first iteration:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc corr data=d1 spearman;
var item1_T1;
with ref1_T1 ref2_T1 ref3_T1 ref4_T1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I think i need a small loop to go over the elements of ref_list and append the tmpt value to each ref var name and then create a new macro variable, like ref_list_tmpt, to be called at the WITH statement, but haven't been able to figure out how to successfully create this ref_list_tmpt.&amp;nbsp; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Any help, better approaches to do this, or direction to resources would be greatly appreciated!&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 29 Apr 2021 21:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738035#M230150</guid>
      <dc:creator>houcr</dc:creator>
      <dc:date>2021-04-29T21:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do i modify all elements of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738039#M230152</link>
      <description>Out of curiousity, what do you get out of looping it 1 by 1 rather than just passing all? Do your variables have systemic names as shown?&lt;BR /&gt;&lt;BR /&gt;I would probably suggesting running it once in a massive run and then parsing through the output parts of interest only which you can capture via ODS tables instead.&lt;BR /&gt;Otherwise, look up some macro utilities to add a prefix to macro variable lists and one to add suffix. &lt;BR /&gt;Prefix macro;&lt;BR /&gt;&lt;A href="http://www.datasavantconsulting.com/roland/Spectre/utilmacros/prefix.sas" target="_blank"&gt;http://www.datasavantconsulting.com/roland/Spectre/utilmacros/prefix.sas&lt;/A&gt;&lt;BR /&gt;Suffix Macro:&lt;BR /&gt;&lt;A href="http://www.datasavantconsulting.com/roland/Spectre/utilmacros/suffix.sas" target="_blank"&gt;http://www.datasavantconsulting.com/roland/Spectre/utilmacros/suffix.sas&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.datasavantconsulting.com/roland/Spectre/maclist2.html#util" target="_blank"&gt;http://www.datasavantconsulting.com/roland/Spectre/maclist2.html#util&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc corr data=d1 spearman;&lt;BR /&gt;var item1_T:;&lt;BR /&gt;with ref:;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 29 Apr 2021 22:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738039#M230152</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-29T22:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do i modify all elements of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738043#M230153</link>
      <description>&lt;P&gt;Like this?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro corr ( data      = d1
&amp;nbsp; &amp;nbsp;         , item_list = item1 item2 item3 item4
&amp;nbsp; &amp;nbsp;         , tmpt      = T1
            , ref_list  = ref1 ref2 ref3 ref4      );&amp;nbsp;

  %local i with item;

  %do i=1 %to %sysfunc(countw(&amp;amp;ref_list));
    %let with=&amp;amp;with %scan(&amp;amp;ref_list, &amp;amp;i)_&amp;amp;tmpt.;
  %end;

  %do i=1 %to %sysfunc(countw(&amp;amp;item_list));
    %let item=%scan(&amp;amp;item_list, &amp;amp;i);
    proc corr data=&amp;amp;data. spearman;
      var &amp;amp;item._&amp;amp;tmpt.;
      with &amp;amp;with. ;
    run;
  %end;&lt;BR /&gt;
%mend;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 22:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738043#M230153</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-29T22:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do i modify all elements of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738044#M230154</link>
      <description>&lt;P&gt;Hi - thanks for the response! The variables names are not systematic in either the item_list or the ref_list. We have fixed non-SAS table formats that we need to populate so I was trying to have the produced output (which i do use ODS tables to extract values from and is processed further in currently non-relevant parts of the macro) mirror the individual final tables as much as possible, so if the code is audited it's clear where tabled values come from in output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will take a look at the provided links. (the suffix macro does exactly what I needed. THANK YOU!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 22:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738044#M230154</guid>
      <dc:creator>houcr</dc:creator>
      <dc:date>2021-04-29T22:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do i modify all elements of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738045#M230155</link>
      <description>Thanks! this works great with minimal modification needed to existing code</description>
      <pubDate>Thu, 29 Apr 2021 22:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-modify-all-elements-of-a-macro-variable/m-p/738045#M230155</guid>
      <dc:creator>houcr</dc:creator>
      <dc:date>2021-04-29T22:34:17Z</dc:date>
    </item>
  </channel>
</rss>

