<?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: Keep a list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449704#M113222</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select distinct var into :varnames separated by ' ' from listvar;
quit;

data bigdata;
    set bigdata(keep=&amp;amp;varnames);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 29 Mar 2018 15:39:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-03-29T15:39:31Z</dc:date>
    <item>
      <title>Keep a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449698#M113218</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I have 2 files. One is a big datafile, and one is the list of variable name and want to keep.&lt;/P&gt;
&lt;P&gt;basically I want something like that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want; set bigfile;&lt;/P&gt;
&lt;P&gt;keep a b c; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the list is long and keep in the second file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me with that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try to transpose and create a temp code like "KEEP a b c ;"&lt;/P&gt;
&lt;P&gt;then do&lt;/P&gt;
&lt;P&gt;data want ; set bigdata;&lt;BR /&gt;%include tmp;&lt;BR /&gt; ;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but dont know how to create that&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;"KEEP a b c ;"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data bigdata; 
input a b c d e f;
datalines;
1 2 3 4 5 6
;run;


data listvar; 
input var $;
datalines;
a
b
c
;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 15:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449698#M113218</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-03-29T15:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Keep a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449701#M113220</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data bigdata; 
input a b c d e f;
datalines;
1 2 3 4 5 6
;run;

data listvar; 
input var $;
datalines;
a
b
c
;
run;
proc sql noprint;
    select var into: varlist separated by ' '
    from listvar;
quit;

data smalldata;
   set bigdata (keep=&amp;amp;varlist.);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 15:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449701#M113220</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-29T15:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Keep a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449704#M113222</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select distinct var into :varnames separated by ' ' from listvar;
quit;

data bigdata;
    set bigdata(keep=&amp;amp;varnames);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 15:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449704#M113222</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-29T15:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: Keep a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449705#M113223</link>
      <description>&lt;P&gt;1. Create a macro variable list from listvar table - see PROC SQL create macro variables in the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See example 3 in the documentation here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1y2jszlvs4hugn14nooftfrxhp3.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0siuil5847r0fn10mbzm8h238ox" target="_blank"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1y2jszlvs4hugn14nooftfrxhp3.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0siuil5847r0fn10mbzm8h238ox&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use that macro variable in a Keep statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;keep &amp;amp;keep_list;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Mar 2018 15:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449705#M113223</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-29T15:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Keep a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449709#M113225</link>
      <description>&lt;P&gt;You already have a solution, but I noticed that no one showed you how to accomplish the task the way you originally wanted to do it. Here is one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data keepers;
  input keepers $;
  datalines;
Name
age
;

data _null_;
  file '/folders/myfolders/keepers.sas';
  set keepers end=lastone;
  if _n_ eq 1 then put 'keep';
  put keepers;
  if lastone then put ';';
run;

data want;
  set sashelp.class;
  %inc '/folders/myfolders/keepers.sas';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 15:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449709#M113225</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-29T15:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Keep a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449716#M113227</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;I thought I will you some sort of transpose, array, then catt() to add these var together.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 16:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-a-list-of-variables/m-p/449716#M113227</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-03-29T16:10:12Z</dc:date>
    </item>
  </channel>
</rss>

