<?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: Macro variable with multiple values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397968#M278335</link>
    <description>&lt;P&gt;Try this....&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 Var1 = Name sex race occp;
%let Var2 = Name age sex salary race country;

data 
   STRING1 (keep=string1  where=(string1 is not missing) )
   STRING2 (keep=string2  where=(string2  is not missing) );

  VAR1=upcase("&amp;amp;var1");
  Var1wc=countw(var1);

  var2=upcase("&amp;amp;var2");
  var2wc=countw(var2);

do i=1 to max(var1wc,var2wc);
  length string1 string2 $32;

  string1 =scan(var1,i," ");
  string2 =scan(var2,i," ");
  output;
end;

run;


proc sql noprint;
  select coalescec(string1 ,string2 ) into: var3 separated by " ";
from WANT A , WANT B
where string1= string2 ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2017 01:00:20 GMT</pubDate>
    <dc:creator>ShiroAmada</dc:creator>
    <dc:date>2017-09-22T01:00:20Z</dc:date>
    <item>
      <title>Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397740#M278330</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having &amp;nbsp;Macro var1 having multiple values seperated by delimitor (master list of charcter type variable), another macro var2 val seperated by dilimitor (another subgroup of Mixed type (Char+Num) ). i want to find out the common values between two macro variables. any one please help me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Macro Var1 = Name sex race occp &amp;nbsp; &amp;nbsp; {all character type variables}&lt;/P&gt;&lt;P&gt;Macro Var2 = Name age sex salary race country {mixed type char and Num variables}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solution Like &amp;nbsp;Macro Var3 = Name sex race &amp;nbsp; {only characters type vars&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 11:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397740#M278330</guid>
      <dc:creator>vikram_e</dc:creator>
      <dc:date>2017-09-21T11:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397743#M278331</link>
      <description>&lt;P&gt;EDIT: this post can be ignored ... should not post without sufficient caffeine consumed.&lt;/P&gt;&lt;P&gt;With the names alone it is impossible to tell whether a variable is numeric or alphanumeric. You need the names of dataset and library and query sashelp.vcoulmn or another metadata-source.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can select variables depending on there type from sashelp.column.&lt;/P&gt;&lt;P&gt;Untested code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select *
     from sashelp.vcolumn
       where libname = 'SASHELP' and MemName = 'CLASS' and Type = 'char'
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 12:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397743#M278331</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-09-21T12:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397753#M278332</link>
      <description>&lt;P&gt;So you have these macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let charvars = Name sex race occp ;
%let allvars = Name age sex salary race country ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you want to produce.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let found=Name sex race;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It would be easier to do it with a data step (if the values of the macro variables are not longer than 32K characters).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  charvars="&amp;amp;charvars";
  allvars="&amp;amp;allvars";
  length found $32767 ;
  do i=1 to countw(charvars,' ');
    if indexw(upcase(allvars),upcase(scan(charvars,i,' '))) then 
      found=catx(' ',found,scan(charvars,i,' '))
    ;
  end;
  call symputx('found',found);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although you could do it inside of a macro. &amp;nbsp;You could even define the macro to work like a function since it has no need to generate SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro findwords(allvars,charvars);
%local i next found ;
%do i=1 %to %sysfunc(countw(&amp;amp;charvars,%str( )));
  %let next=%scan(&amp;amp;charvars,&amp;amp;i,%str( ));
  %if %sysfunc(indexw(%upcase(&amp;amp;allvars),%upcase(&amp;amp;next),%str( ))) %then
    %let found=&amp;amp;found &amp;amp;next 
  ;
%end;
&amp;amp;found.
%mend findwords;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could call it to create your list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let found=%findwords(&amp;amp;allvars,&amp;amp;charvars);
%put &amp;amp;=found ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 12:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397753#M278332</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-21T12:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397759#M278333</link>
      <description>&lt;P&gt;Excellent advice.&amp;nbsp; Also note, you can get rid of the local macro variable FOUND.&amp;nbsp; Remove it from the %LOCAL statement, remove the final &amp;amp;FOUND. line, and make this change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token macrostatement"&gt;%if&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;indexw&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%upcase&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;allvars&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%upcase&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;next&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%str&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%then &lt;STRONG&gt;&lt;FONT color="#00ccff"&gt;&amp;amp;next&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 13:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397759#M278333</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-21T13:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397968#M278335</link>
      <description>&lt;P&gt;Try this....&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 Var1 = Name sex race occp;
%let Var2 = Name age sex salary race country;

data 
   STRING1 (keep=string1  where=(string1 is not missing) )
   STRING2 (keep=string2  where=(string2  is not missing) );

  VAR1=upcase("&amp;amp;var1");
  Var1wc=countw(var1);

  var2=upcase("&amp;amp;var2");
  var2wc=countw(var2);

do i=1 to max(var1wc,var2wc);
  length string1 string2 $32;

  string1 =scan(var1,i," ");
  string2 =scan(var2,i," ");
  output;
end;

run;


proc sql noprint;
  select coalescec(string1 ,string2 ) into: var3 separated by " ";
from WANT A , WANT B
where string1= string2 ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 01:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397968#M278335</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-22T01:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397977#M278336</link>
      <description>&lt;P&gt;Hi Tom&lt;/P&gt;&lt;P&gt;Thanks for your time to solve the issue, i appriciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 04:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397977#M278336</guid>
      <dc:creator>vikram_e</dc:creator>
      <dc:date>2017-09-22T04:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397978#M278337</link>
      <description>&lt;P&gt;Hi ShiroAmanda,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time, Code was simple and easy to understand to every one. i appriciate your help.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 04:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-multiple-values/m-p/397978#M278337</guid>
      <dc:creator>vikram_e</dc:creator>
      <dc:date>2017-09-22T04:32:48Z</dc:date>
    </item>
  </channel>
</rss>

