<?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: SAS:how to use index to pick out macro array variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441979#M110554</link>
    <description>&lt;P&gt;thank you.most of the answers are helpful,but yours is the best one with expanded knowledge and well explained.&lt;/P&gt;</description>
    <pubDate>Sat, 03 Mar 2018 00:26:41 GMT</pubDate>
    <dc:creator>Geo-</dc:creator>
    <dc:date>2018-03-03T00:26:41Z</dc:date>
    <item>
      <title>SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441511#M110469</link>
      <description>&lt;DIV class="post-text"&gt;&lt;P&gt;I create a marco array using:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc sql;
select distinct variable into:numVarList separated by ' ' from Map_num;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I used:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%put &amp;amp;numVarList{1};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and it gave me all variables:&lt;CODE&gt;var1 var2 var3{1}&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;how to use index to pick out macro array variable?&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441511#M110469</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-03-02T09:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441512#M110470</link>
      <description>&lt;P&gt;Use scan function&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441512#M110470</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-03-02T09:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441515#M110472</link>
      <description>&lt;P&gt;would you please give me the exact code using scan.thank you&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441515#M110472</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-03-02T09:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441521#M110475</link>
      <description>&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question really is what are you intending to do with a list in a macro variable.&amp;nbsp; It is a question which repeatedly comes up on the forums, and all I ever see it doing is creating masses of messy macro code, which falls over half the time.&amp;nbsp; It really isn't a good way to be programming, and 99% of the time can be alleviated by simply re-thinking the problem.&amp;nbsp; Show what you use that macro for and I can explain further.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441521#M110475</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-02T09:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441523#M110477</link>
      <description>&lt;P&gt;For use in macro language, there's the &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#z3514scan.htm" target="_blank"&gt;%scan()&lt;/A&gt; function.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441523#M110477</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-02T09:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441524#M110478</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct variable into:numVarList separated by ' ' from Map_num;
quit;

%put &amp;amp;numVarList.;

%put %sysfunc(scan(&amp;amp;numVarList.,1));
%put %sysfunc(scan(&amp;amp;numVarList.,2));
%put %sysfunc(scan(&amp;amp;numVarList.,3));
%put %sysfunc(scan(&amp;amp;numVarList.,4));
%put %sysfunc(scan(&amp;amp;numVarList.,5));
%put %sysfunc(scan(&amp;amp;numVarList.,6));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441524#M110478</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-02T09:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441537#M110487</link>
      <description>&lt;P&gt;There is no such thing as a macro array. You can simulate arrays in macros in two ways:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;As you did, put the stuff into a single string, with a delimiter (blank in your case).&lt;/LI&gt;&lt;LI&gt;Generate a number of macro variables with the same prefix.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;In case one, you can use the %SCAN macro function, (or, if you have quoted delimiters, %sysfunc(SCAN()) with the Q option) to access individual elements, in your case&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(&amp;amp;numVarlist,1,str( ));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You could also use the second solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
  select distinct variable into: numVar1-numVar999 from Map_num:&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In which case you can get the first element like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;numVar1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or, if you are using macro variables to access the "array":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let i=1;
%put &amp;amp;&amp;amp;numVar&amp;amp;i;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The double ampersand works like this: the macro interpreter scans the codes several times. Each time, double ampersands become single ampersands, and "unmatched" ampersands trigger interpretation of variables. So, after the first scan, &amp;amp;&amp;amp;numVar&amp;amp;i becomes &amp;amp;numVar1, in the second scan that becomes the value (var1 in your example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using the first method, you can use the COUNTW function to find the number of values, with the second option, it is not so obvious (you may look at which macro variables exist, but then, they may be variables generated in an earlier, similar SQL call). So in any case I advice you to store the value of the SQLobs macro variable after the SQL call:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
  select distinct variable into: numVar1-numVar999 from Map_num:
  %let nVars=&amp;amp;SQLobs;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Mar 2018 11:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441537#M110487</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-02T11:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441979#M110554</link>
      <description>&lt;P&gt;thank you.most of the answers are helpful,but yours is the best one with expanded knowledge and well explained.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Mar 2018 00:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/441979#M110554</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-03-03T00:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/442215#M110612</link>
      <description>&lt;P&gt;it is strange that&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%put &amp;amp;numVarList.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;then I got:age agenc_non_ccbt_fnd_bal chmtpd_tmpnt_bal crnyr_cnter_tdnum&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%put %sysnc(scan(&amp;amp;numVarList.,1,str( )));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I got:age agnc_non_ccb&lt;/P&gt;&lt;P&gt;why?and how to fix it?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 01:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/442215#M110612</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-03-05T01:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/442220#M110614</link>
      <description>&lt;DIV class="lia-message-body lia-component-body"&gt;&lt;DIV class="lia-message-body-content"&gt;hi,using code below will not return char type value,how to fix?&lt;BR /&gt;&lt;PRE&gt;&lt;CODE&gt;%put %sysnc(scan(&amp;amp;numVarList.,1));&lt;/CODE&gt;&lt;/PRE&gt;exact case,this will work:&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;proc sql;&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;create table tableA as&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;select columnA into:valueA separated by ' ' from Map_num&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;where variable='age';&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;and this couldn't work,the error shows could not find column age&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;DIV class="lia-message-body-content"&gt;create table tableA as&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;select columnA into:valueA separated by ' ' from Map_num&lt;/DIV&gt;where variable=%sysnc(scan(&amp;amp;numVarList.,1));&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-message-body-content"&gt;why and how to fix it?&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 05 Mar 2018 02:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/442220#M110614</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-03-05T02:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS:how to use index to pick out macro array variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/442254#M110630</link>
      <description>&lt;P&gt;How should we validate this code without having the dataset map_num?&lt;/P&gt;
&lt;P&gt;Please post example data in a data step, eg by using the macro from &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184018"&gt;@Geo-&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;DIV class="lia-message-body lia-component-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;hi,using code below will not return char type value,how to fix?&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;%put %sysnc(scan(&amp;amp;numVarList.,1));&lt;/CODE&gt;&lt;/PRE&gt;
exact case,this will work:&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;proc sql;&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;create table tableA as&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;select columnA into:valueA separated by ' ' from Map_num&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;where variable='age';&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;and this couldn't work,the error shows could not find column age&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;DIV class="lia-message-body-content"&gt;create table tableA as&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;select columnA into:valueA separated by ' ' from Map_num&lt;/DIV&gt;
where variable=%sysnc(scan(&amp;amp;numVarList.,1));&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="lia-message-body-content"&gt;why and how to fix it?&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 06:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-use-index-to-pick-out-macro-array-variable/m-p/442254#M110630</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-05T06:37:06Z</dc:date>
    </item>
  </channel>
</rss>

