<?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: Selecting values from a macro array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/345995#M273181</link>
    <description>&lt;P&gt;You shouldn't embed a macro within a data step. You're mixing data step and macro logic. So...what are you trying to do overall?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think a temporary array may be a better solution - use the macro variable to create the array if you like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array myNum(*) _temporary_ (&amp;amp;devv1_list); &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dev1 = myNum(year - 2006);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call symputx('dev1', dev1, 'g');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;dev1;&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2017 00:19:53 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-31T00:19:53Z</dc:date>
    <item>
      <title>Selecting values from a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/345994#M273180</link>
      <description>&lt;P&gt;I have several multi-dimensional arrays I need to use in a very large dataset.&amp;nbsp;&amp;nbsp; Rather than trying to merge them, I thought it might be more efficient to create macro arrays and them selectively assign macro values in the large data set with do loops.&amp;nbsp;&amp;nbsp; However, I've run into an issue.&amp;nbsp;&amp;nbsp; The Do Loop is not "1 to X" but rather "2006 to 2014."&amp;nbsp;&amp;nbsp;&amp;nbsp; %eval will not read my formula (see row 30).&amp;nbsp;&amp;nbsp; Any suggestions on a better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;26 %let DedV1_list=472 495 516 524 538 540 540 550;&lt;/P&gt;&lt;P&gt;27 Data _null_;&lt;/P&gt;&lt;P&gt;28 Year=2007;&lt;/P&gt;&lt;P&gt;29 %macro rap;&lt;/P&gt;&lt;P&gt;30 %let Ded=%scan(&amp;amp;DedV1_list,%eval(year-2006));&lt;/P&gt;&lt;P&gt;31 %put &amp;amp;DEd;&lt;/P&gt;&lt;P&gt;32 %mend;&lt;/P&gt;&lt;P&gt;33 %rap&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable DEDV1_LIST resolves to 472 495 516 524 538 540 540 550&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;/P&gt;&lt;P&gt;year-2006&lt;/P&gt;&lt;P&gt;WARNING: Argument 2 to macro function %SCAN is out of range.&lt;/P&gt;&lt;P&gt;ERROR: The macro RAP will stop executing.&lt;/P&gt;&lt;P&gt;34 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 00:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/345994#M273180</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2017-03-31T00:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting values from a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/345995#M273181</link>
      <description>&lt;P&gt;You shouldn't embed a macro within a data step. You're mixing data step and macro logic. So...what are you trying to do overall?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think a temporary array may be a better solution - use the macro variable to create the array if you like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array myNum(*) _temporary_ (&amp;amp;devv1_list); &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dev1 = myNum(year - 2006);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call symputx('dev1', dev1, 'g');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;dev1;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 00:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/345995#M273181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-31T00:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting values from a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/346004#M273182</link>
      <description>&lt;P&gt;Not sure you should be putting data into macro variables, but your example looks pretty simple.&lt;/P&gt;
&lt;P&gt;You could just use a SCAN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let DedV1_list=472 495 516 524 538 540 540 550;

data want ;
  set have ;
  ded = input(scan("&amp;amp;dedv1_list",year - 2006),32.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could make a temporary array in your data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  array dedv1_list (%sysfunc(countw(&amp;amp;dedv1_list))) _temporary_ (&amp;amp;dedv1_list);
  set have ;
  ded = dedv1_list(year - 2006) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 01:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-values-from-a-macro-array/m-p/346004#M273182</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-31T01:00:00Z</dc:date>
    </item>
  </channel>
</rss>

