<?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 to populate the values into macro varaible in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535388#M147007</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
input country $ ; 
datalines;
ind
afr
sa
na
eu
aus
;
run;

 

data test;
input country $ transaction;
datalines;
ind 20
gbr 30
usa 40
aus 50
sa 60
na 70
eu 80
afr 15
zim 17
tx 89
china 88
japan 76
;
run;

proc sql;
create table want as
select a.*,transaction
from temp a left join test b
on a.country=b.country;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Feb 2019 20:10:44 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-02-13T20:10:44Z</dc:date>
    <item>
      <title>How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535381#M147005</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;i have two datasets as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data temp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input country $ ; &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ind&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;afr&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;sa&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;na&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;eu&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;aus&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data test;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input country $ transaction;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ind 20&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;gbr 30&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;usa 40&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;aus 50&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;sa 60&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;na 70&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;eu 80&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;afr 15&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;zim 17&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;tx 89&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;china 88&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;japan 76&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;i want all the countries from dataset temp copied into macro variable&lt;/FONT&gt; such that my result&amp;nbsp; in &lt;STRONG&gt;dataset want&lt;/STRONG&gt; should be like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;And also please suggest any other possible ways which i can implement to get the result.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;country transaction&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ind&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;afr&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;sa&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;na&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;eu&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;aus&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535381#M147005</guid>
      <dc:creator>subhani4</dc:creator>
      <dc:date>2019-02-13T20:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535387#M147006</link>
      <description>&lt;P&gt;No macros or macro variables are needed. Either PROC SQL or simple data step merge will get you what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE BECAUSE I HAVE A MEETING IN 2 MINUTES&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    merge temp(in=in1) test;
    by country;
    if in1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Advice: macros should be your last choice for manipulating data, used only when you can't get data steps or SQL or SAS PROCs to do what you want; or when you need the code to be dynamic somehow.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535387#M147006</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-13T20:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535388#M147007</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
input country $ ; 
datalines;
ind
afr
sa
na
eu
aus
;
run;

 

data test;
input country $ transaction;
datalines;
ind 20
gbr 30
usa 40
aus 50
sa 60
na 70
eu 80
afr 15
zim 17
tx 89
china 88
japan 76
;
run;

proc sql;
create table want as
select a.*,transaction
from temp a left join test b
on a.country=b.country;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535388#M147007</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-13T20:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535389#M147008</link>
      <description>&lt;P&gt;Use a format, or do a join. No need to involve the macro preprocessor.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535389#M147008</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-13T20:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535392#M147011</link>
      <description>Could any one help me with call symputx function to perform the task. Thanks in advance!!</description>
      <pubDate>Wed, 13 Feb 2019 20:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535392#M147011</guid>
      <dc:creator>subhani4</dc:creator>
      <dc:date>2019-02-13T20:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535400#M147014</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set temp end=lr;
length t $100;
retain t;
t=catx(',',t,quote(strip(country)));
if lr then call symputx('t',t);
run;
%put &amp;amp;t;

data want;
set test;
if country in (&amp;amp;t);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535400#M147014</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-13T20:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535403#M147015</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109262"&gt;@subhani4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Could any one help me with call symputx function to perform the task. Thanks in advance!!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As others have indicated this won't work. I have no idea how you'd use those macro variables after the fact. Regardless, here's one option on how to create a list of macro variables easily that will be useful. I strongly recommend against using this and the only use I can conceive of is either homework or a pass-through query, but even then, there are other better methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql NOPRINT;

select quote(name) into :name_list separated by ", " from sashelp.class;

quit;

proc sql noprint;
select name into :name1- from sashelp.class;
quit;

%put Name_List: &amp;amp;name_list:

%put Name1 : &amp;amp;name1.;

%put Name2: &amp;amp;name19.;

data _null_;
set sashelp.class;
call symputx(catx("_", 'MacroName', _n_), name);
run;

%put MacroName1 : &amp;amp;macroName1.;
%put MacroName19 : &amp;amp;macroName19.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535403#M147015</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-13T20:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535405#M147016</link>
      <description>&lt;P&gt;Please &lt;STRIKE&gt;post your data as a data step in the future and&lt;/STRIKE&gt; ensure that code is enclosed in code blocks. This makes it easier to copy and paste your data/code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&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" rel="noopener"&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;P&gt;My apologies, you did do that.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109262"&gt;@subhani4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;i have two datasets as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data temp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input country $ ; &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ind&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;afr&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;sa&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;na&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;eu&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;aus&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data test;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input country $ transaction;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ind 20&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;gbr 30&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;usa 40&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;aus 50&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;sa 60&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;na 70&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;eu 80&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;afr 15&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;zim 17&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;tx 89&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;china 88&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;japan 76&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;i want all the countries from dataset temp copied into macro variable&lt;/FONT&gt; such that my result&amp;nbsp; in &lt;STRONG&gt;dataset want&lt;/STRONG&gt; should be like below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;And also please suggest any other possible ways which i can implement to get the result.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;country transaction&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ind&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;afr&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;sa&lt;/TD&gt;
&lt;TD&gt;60&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;na&lt;/TD&gt;
&lt;TD&gt;70&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;eu&lt;/TD&gt;
&lt;TD&gt;80&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;aus&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 20:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535405#M147016</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-13T20:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to populate the values into macro varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535495#M147055</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109262"&gt;@subhani4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Could any one help me with call symputx function to perform the task. Thanks in advance!!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;call symputx is a macro-related subroutine.&lt;/P&gt;
&lt;P&gt;I repeat: &lt;STRONG&gt;YOU DO NOT NEED THE MACRO PREPROCESSOR FOR THIS.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 06:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-populate-the-values-into-macro-varaible/m-p/535495#M147055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-14T06:23:56Z</dc:date>
    </item>
  </channel>
</rss>

