<?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 Concatenation of Dynamically Generated Macro into a new Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637684#M189560</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to concatenate dynamically generated macro variables into a new macro variable for my further use. As per my below code there are some variable are stored in my "Table1" dataset. I took a unique count into co variable and name of all variable in macro variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;DATA_IN1&amp;nbsp;,DATA_IN2.....etc.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one more VVV dataset where some more variable are present as prefix name same as&amp;nbsp;"Table1" . VVV tables contains more the one variable as the prefix . i want to take all the variable name from VVV tables which was present in Table1 with prefix name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex: In table1 - two variable like - name&amp;nbsp; address&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; In VVV table - variable name like -name name_middle name_last address_Pin address_code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output needed into new macro variable as : new_macro_var =&amp;nbsp;name name_middle name_last address_Pin address_code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO Concat_Macro;
%DO I=1 %TO &amp;amp;CO.;
PROC SQL NOPRINT;
SELECT NAME INTO :IN&amp;amp;I. SEPARATED BY ' ' FROM VVV WHERE NAME LIKE "&amp;amp;&amp;amp;DATA_IN&amp;amp;I..%";
QUIT;
%PUT &amp;amp;&amp;amp;IN&amp;amp;I.;
%END;
%MEND;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm not sure which statement will help me to concatenate it. Above is my sample code . It didn't contain concatenate details .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance !!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Apr 2020 13:47:05 GMT</pubDate>
    <dc:creator>singhsahab</dc:creator>
    <dc:date>2020-04-05T13:47:05Z</dc:date>
    <item>
      <title>Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637684#M189560</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to concatenate dynamically generated macro variables into a new macro variable for my further use. As per my below code there are some variable are stored in my "Table1" dataset. I took a unique count into co variable and name of all variable in macro variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;DATA_IN1&amp;nbsp;,DATA_IN2.....etc.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one more VVV dataset where some more variable are present as prefix name same as&amp;nbsp;"Table1" . VVV tables contains more the one variable as the prefix . i want to take all the variable name from VVV tables which was present in Table1 with prefix name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex: In table1 - two variable like - name&amp;nbsp; address&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; In VVV table - variable name like -name name_middle name_last address_Pin address_code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output needed into new macro variable as : new_macro_var =&amp;nbsp;name name_middle name_last address_Pin address_code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO Concat_Macro;
%DO I=1 %TO &amp;amp;CO.;
PROC SQL NOPRINT;
SELECT NAME INTO :IN&amp;amp;I. SEPARATED BY ' ' FROM VVV WHERE NAME LIKE "&amp;amp;&amp;amp;DATA_IN&amp;amp;I..%";
QUIT;
%PUT &amp;amp;&amp;amp;IN&amp;amp;I.;
%END;
%MEND;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm not sure which statement will help me to concatenate it. Above is my sample code . It didn't contain concatenate details .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance !!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 13:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637684#M189560</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2020-04-05T13:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637685#M189561</link>
      <description>&lt;P&gt;Please show us a portion of the data set(s) you are talking about.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 13:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637685#M189561</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-05T13:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637686#M189562</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Below is the data portion . Please Note . I don't want to merge these two tables. I need to take variables name from VVV dataset based on table1 datset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
length name address $20.;
input name address;
datalines;
AAA Bangalore
BBB Delhi
;
run;

data Table1;
length name name_middle name_last $20.;
input name name_middle name_last address_Pin address_code;
datalines;
shy singh G 23130 91
kk kumar  G 45678 91
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Apr 2020 14:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637686#M189562</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2020-04-05T14:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637687#M189563</link>
      <description>&lt;P&gt;That is not at all clear, please show example input and expected output.&lt;/P&gt;
&lt;P&gt;Why do you feel the need to take data from datasets put it into macro variables then use the macro variables to query other datasets? Why not just combine the two datasets directly and skip the translates to/from text required to but the data into macro variables?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 14:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637687#M189563</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-05T14:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637690#M189566</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Here is my code&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
length name address $20.;
input name address;
datalines;
AAA Bangalore
BBB Delhi
;
run;

data Table12;
length name name_middle name_last $20.;
input name name_middle name_last address_Pin address_code Area_code area_pin;
datalines;
shy singh G 23130 91 12 2
kk kumar  G 45678 91 23 1
;
run;

PROC SQL NOPRINT;
SELECT COUNT(DISTINCT(name)) INTO :CO FROM DICTIONARY.COLUMNS WHERE LIBNAME LIKE 'WORK' AND MEMNAME LIKE 'TABLE1'; 
SELECT DISTINCT(name) INTO :DATA_IN1 - :DATA_IN%LEFT(&amp;amp;CO) FROM DICTIONARY.COLUMNS WHERE LIBNAME LIKE 'WORK' AND MEMNAME LIKE 'TABLE1';
CREATE TABLE VVV AS 
SELECT NAME  FROM DICTIONARY.COLUMNS WHERE LIBNAME LIKE 'WORK' AND MEMNAME LIKE 'TABLE12';
RUN;


/*OPTIONS MPRINT MLOGIC SYMBOLGEN;*/
%MACRO Concat_Macro;

%DO I=1 %TO &amp;amp;CO.;

PROC SQL NOPRINT;
SELECT NAME INTO :IN&amp;amp;I. SEPARATED BY ' ' FROM VVV WHERE NAME LIKE "&amp;amp;&amp;amp;DATA_IN&amp;amp;I..%";
QUIT;
%PUT &amp;amp;&amp;amp;IN&amp;amp;I.;
%END;
%MEND;

%Concat_Macro;


--I want only "name name_middle name_last address_Pin address_code" varibale from table12,if Prefiex text is present in Table1, extra variable i don't want to take .
--I have one more macro where i need to pass all these variable dynamically through one macro variable so i can get final output as below 

name name_middle name_last address_Pin address_code
shy singh G 23130 91 
kk kumar  G 45678 91 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Apr 2020 14:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637690#M189566</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2020-04-05T14:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637713#M189586</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153275"&gt;@singhsahab&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Below is the data portion . Please Note . I don't want to merge these two tables. I need to take variables name from VVV dataset based on table1 datset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
length name address $20.;
input name address;
datalines;
AAA Bangalore
BBB Delhi
;
run;

data Table1;
length name name_middle name_last $20.;
input name name_middle name_last address_Pin address_code;
datalines;
shy singh G 23130 91
kk kumar  G 45678 91
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is no VVV data set.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637713#M189586</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-05T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation of Dynamically Generated Macro into a new Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637723#M189594</link>
      <description>&lt;P&gt;Your explanation seems to have skipped a few tracks on the record.&lt;/P&gt;
&lt;P&gt;Reading between the lines it looks like you want NAMES of the variables in TABLE12 whose NAMES are extensions of the NAMES of the variables in TABLE1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
select distinct a.varnum, a.name 
  into :dummy , :namelist separated by ' '
  from dictionary.columns a
     , dictionary.columns b
  where a.libname="WORK" and a.memname="TABLE12"
    and b.libname="WORK" and b.memname="TABLE1"
    and upcase(a.name) like upcase(cats(b.name,'%'))
  order by 1
;
%let n=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;881   %put &amp;amp;=n &amp;amp;=namelist;
N=5 NAMELIST=name name_middle name_last address_Pin address_code
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 19:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-of-Dynamically-Generated-Macro-into-a-new-Macro/m-p/637723#M189594</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-05T19:45:30Z</dc:date>
    </item>
  </channel>
</rss>

