<?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 Select variables from dataframe1 using a list of column names in dataframe2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603013#M174667</link>
    <description>&lt;P&gt;I have a large data frame already formatted the way I desire with several thousand columns called df1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;col1 col2 col3 .... col5000&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;...&amp;nbsp; &amp;nbsp; &amp;nbsp;....&amp;nbsp; &amp;nbsp;...&amp;nbsp; &amp;nbsp; &amp;nbsp;....&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've selected a few hundred of these columns to use as features and have the list stored in a separate dataframe, df2.&lt;/P&gt;&lt;P&gt;ColN&lt;/P&gt;&lt;P&gt;col1&lt;/P&gt;&lt;P&gt;col3&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;col5000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The list is approx. 1000 entries and are not sequential. How can I select the columns from df1 so that my final result is something like&lt;/P&gt;&lt;P&gt;col1&amp;nbsp; col3 .... col5000&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;....&amp;nbsp; &amp;nbsp; ....&amp;nbsp; &amp;nbsp; ....&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I've tried something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table 
	df_subset as
select 
	A.* in(B.colN) 
from 
	df1 as A, 
	df2 as B
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am currently working in SAS studio&lt;/P&gt;</description>
    <pubDate>Sat, 09 Nov 2019 20:54:58 GMT</pubDate>
    <dc:creator>rschubert1</dc:creator>
    <dc:date>2019-11-09T20:54:58Z</dc:date>
    <item>
      <title>Select variables from dataframe1 using a list of column names in dataframe2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603013#M174667</link>
      <description>&lt;P&gt;I have a large data frame already formatted the way I desire with several thousand columns called df1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;col1 col2 col3 .... col5000&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;...&amp;nbsp; &amp;nbsp; &amp;nbsp;....&amp;nbsp; &amp;nbsp;...&amp;nbsp; &amp;nbsp; &amp;nbsp;....&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've selected a few hundred of these columns to use as features and have the list stored in a separate dataframe, df2.&lt;/P&gt;&lt;P&gt;ColN&lt;/P&gt;&lt;P&gt;col1&lt;/P&gt;&lt;P&gt;col3&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;col5000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The list is approx. 1000 entries and are not sequential. How can I select the columns from df1 so that my final result is something like&lt;/P&gt;&lt;P&gt;col1&amp;nbsp; col3 .... col5000&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; .... 1&lt;/P&gt;&lt;P&gt;....&amp;nbsp; &amp;nbsp; ....&amp;nbsp; &amp;nbsp; ....&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I've tried something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table 
	df_subset as
select 
	A.* in(B.colN) 
from 
	df1 as A, 
	df2 as B
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am currently working in SAS studio&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 20:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603013#M174667</guid>
      <dc:creator>rschubert1</dc:creator>
      <dc:date>2019-11-09T20:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select variables from dataframe1 using a list of column names in dataframe2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603017#M174670</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select distinct colN into :wanted_columns separated by ' ' from df2;
quit;

data df_subset;
    set df1(keep=&amp;amp;wanted_columns);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2019 22:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603017#M174670</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-09T22:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select variables from dataframe1 using a list of column names in dataframe2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603020#M174673</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288370"&gt;@rschubert1&lt;/a&gt; Your code doesn't work as you try to use metadata where SQL expects data.&lt;/P&gt;
&lt;P&gt;The method used by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; works.&lt;/P&gt;
&lt;P&gt;Similarly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct colN into :wanted_columns separated by ',' from DF2;
  create table SUBSET as select &amp;amp;wanted_columns from DF1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 22:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603020#M174673</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-11-09T22:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select variables from dataframe1 using a list of column names in dataframe2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603025#M174677</link>
      <description>The term dataframe tells me you're coming from R or Python, SAS uses data sets. Either way, you need to convert that list to a macro variable, similar to creating it as a list in R/Python and then add that to your data frame in a KEEP statement. If you're familiar with R, KEEP is similar in functionality to the SELECT operator in Tidyverse. &lt;BR /&gt;&lt;BR /&gt;PaigeMiller's solution does this, convert the data frame into a variable that can be used in the next steps.</description>
      <pubDate>Sat, 09 Nov 2019 23:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-variables-from-dataframe1-using-a-list-of-column-names-in/m-p/603025#M174677</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-09T23:41:48Z</dc:date>
    </item>
  </channel>
</rss>

