<?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: select specific column from one table to combine with other table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641872#M191401</link>
    <description>&lt;P&gt;I think I didn't explain my query properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to combine one column variable named as INTERCEPT from each of MYFILES1 table to combine with the MYFILES table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like&lt;/P&gt;
&lt;P&gt;MYFILES.estjan1990 column variable "INTERCEPT" merge with MYFILES.jan1990 table&lt;/P&gt;
&lt;P&gt;MYFILES.estFeb1990 column variable "INTERCEPT"&amp;nbsp;merge with MYFILES.Feb1990 table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I used the below macro which merge all columns but I don't want all columns to merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Macro for multiple sheet*/

%let months = JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC;
%macro ex;
%do year = 1990 %to 2016; /* adapt years as need */
    %do i=1 %to 12;
        %let file = %scan(&amp;amp;months,&amp;amp;i)&amp;amp;year;
        %put FILE=&amp;amp;file;
        /* enter here your code */
       
       data Myest.&amp;amp;file;
	merge myfiles1.&amp;amp;file(in=a) myfiles.myest&amp;amp;file(in=b);
	if b;
run;

/* enter here your code */

    %end;
%end;
%mend ex;
%ex;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope it suffices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sara&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Apr 2020 11:22:59 GMT</pubDate>
    <dc:creator>saraphdnz</dc:creator>
    <dc:date>2020-04-22T11:22:59Z</dc:date>
    <item>
      <title>select specific column from one table to combine with other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641815#M191363</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have multiple sas tables and each table have multiple columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like one library contain tables Myfiles.Jan1990, Myfiles.Feb1990,.... Myfiles.Dec2016&lt;/P&gt;
&lt;P&gt;another library contain tables Myfiles1.estJan1990, Myfiles1.estFeb1990,.....Myfiles1.estDec2016. (same name columns in each table in this library).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to combine a specific column (named as Intercept) from Myfiles1 tables with Myfiles tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to combine a specific column from one table with the bunch of columns in other table? I have attached two files from both libraries for reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sara&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 05:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641815#M191363</guid>
      <dc:creator>saraphdnz</dc:creator>
      <dc:date>2020-04-22T05:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: select specific column from one table to combine with other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641819#M191366</link>
      <description>&lt;P&gt;I'd first see if there was a way to adjust the process that creates all of these separate tables in order to avoid that. If that's not possible, try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Data setup to replicate the datasets you should have;
data _null_;
	start_dt='01JAN1990'd;
	end_dt='01DEC2016'd;
	dt=start_dt;
	i=0;

	do until(dt&amp;gt;end_dt);
		curr_dt=put(dt, monyy7.);
		call execute(catx('', 'data', curr_dt, ';message = "Hi from', curr_dt, 
			'";run;') );
		call execute(catx('', 'data', cats('est', curr_dt), 
			';message2 = "Hi from estimate:', curr_dt, '";run;') );
		i+1;
		dt=intnx('month', start_dt, i, 'b');
	end;
run;

*Get table names -- you may have to adjust WORK to MYFILES;
proc sql;
	create table _tabs as select memname as table_name from dictionary.tables 
		where libname='WORK' and lengthn(memname)=7 order by input(memname, monyy7.);
quit;


/***
Read through table names and execute code that looks like:

data wantJAN1990;
	merge JAN1990(in=a) estJAN1990(in=b);
	if b;
run;

***/

data _null_;
	set _tabs;
	call execute(catx('',
		'data',cats('want', table_name), 
		'; merge',cats(table_name, '(in=a)'), cats('est', table_name, '(in=b)'),
		'; if a; run;'
	));
run;

*Combine all want datasets  together;
data final_want;
	set want:;
run;

*Preview results;
proc print data=final_want(obs=20);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 05:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641819#M191366</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-04-22T05:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: select specific column from one table to combine with other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641865#M191398</link>
      <description>&lt;P&gt;First, stop naming your datasets like this. If you need timeseries, use a properly sorting naming scheme, so estjan1990 has to be called est_1990_01. Create a generic name for the other datasets, if you don't have one, use a simple underline.&lt;/P&gt;
&lt;P&gt;And what is the reason for that massive redundancy in the EST dataset? The only value in there is -1, and it is always in the column named in column _DEPVAR_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the expected result from the intended join?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 09:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641865#M191398</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-22T09:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: select specific column from one table to combine with other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641872#M191401</link>
      <description>&lt;P&gt;I think I didn't explain my query properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to combine one column variable named as INTERCEPT from each of MYFILES1 table to combine with the MYFILES table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like&lt;/P&gt;
&lt;P&gt;MYFILES.estjan1990 column variable "INTERCEPT" merge with MYFILES.jan1990 table&lt;/P&gt;
&lt;P&gt;MYFILES.estFeb1990 column variable "INTERCEPT"&amp;nbsp;merge with MYFILES.Feb1990 table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I used the below macro which merge all columns but I don't want all columns to merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Macro for multiple sheet*/

%let months = JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC;
%macro ex;
%do year = 1990 %to 2016; /* adapt years as need */
    %do i=1 %to 12;
        %let file = %scan(&amp;amp;months,&amp;amp;i)&amp;amp;year;
        %put FILE=&amp;amp;file;
        /* enter here your code */
       
       data Myest.&amp;amp;file;
	merge myfiles1.&amp;amp;file(in=a) myfiles.myest&amp;amp;file(in=b);
	if b;
run;

/* enter here your code */

    %end;
%end;
%mend ex;
%ex;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope it suffices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sara&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 11:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641872#M191401</guid>
      <dc:creator>saraphdnz</dc:creator>
      <dc:date>2020-04-22T11:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: select specific column from one table to combine with other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641895#M191416</link>
      <description>&lt;P&gt;How about these changes to the data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Myest.&amp;amp;file;
merge
  myfiles1.&amp;amp;file (in=a)
  myfiles.myest&amp;amp;file (
    in=b
    keep=_depvar intercept
    rename=(_depvar_=date)
  )
;
by date;
if b;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 11:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/641895#M191416</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-22T11:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: select specific column from one table to combine with other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/642157#M191543</link>
      <description>&lt;P&gt;Thanks KurtBremser - the code worked for me, much appreciated for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Sara&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 04:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-specific-column-from-one-table-to-combine-with-other/m-p/642157#M191543</guid>
      <dc:creator>saraphdnz</dc:creator>
      <dc:date>2020-04-23T04:16:02Z</dc:date>
    </item>
  </channel>
</rss>

