<?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 Process to remove variables from another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30473#M5813</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are sure that every variable named in A.VARS actually appears in&amp;nbsp; A.DATA, here is the method I like.&amp;nbsp; This assumes that VARNAME is the name of the one and only variable in A.VARS:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('data new.data; set a.data (keep=');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (done);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a.vars end=done;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(varname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('); run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The log will show you the statements that get generated.&amp;nbsp; Also, note that ID will be dropped if it is not named in A.VARS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Mar 2012 22:50:24 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2012-03-13T22:50:24Z</dc:date>
    <item>
      <title>Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30466#M5806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I hope someone could help me with this problem: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data file a.data with accounts and their attributes across ~100 variables&lt;/P&gt;&lt;P&gt;I have a list of variables – as a separate file – a.vars,which contains a subset of 100 variables (let’s say 20 of the 100)&lt;/P&gt;&lt;P&gt;I need to code a process that would drop from a.data all variables that are not in a.vars file. It has to be SAS process (not manualwork through EXCEL), that just does it in a completely automated manner.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a.data:&lt;/P&gt;&lt;P&gt;id var1 var2 var3 var4 var5&lt;/P&gt;&lt;P&gt;1 0 1 1 0 1 0&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a.vars:&lt;/P&gt;&lt;P&gt;var1&lt;/P&gt;&lt;P&gt;var2&lt;/P&gt;&lt;P&gt;var3&lt;/P&gt;&lt;P&gt;var6&lt;/P&gt;&lt;P&gt;var7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;new.data&lt;/P&gt;&lt;P&gt;id var1 var2 var3&lt;/P&gt;&lt;P&gt;1 0 1 1 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 21:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30466#M5806</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2012-03-13T21:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30467#M5807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like the following should work (untested). &lt;/P&gt;&lt;P&gt;You could convert it into a macro if required based on the libname, dataset name and output name easily.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;*get columns in your dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table vnames as&lt;/P&gt;&lt;P&gt;select name from dictionary.columns&lt;/P&gt;&lt;P&gt;where libname=your_libname and memname=yourdataset;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Get overlap;&lt;/P&gt;&lt;P&gt;select name into :names separated by " " from vnames&lt;/P&gt;&lt;P&gt;where name in (select names from data name_list);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new_data;&lt;/P&gt;&lt;P&gt;set &amp;lt;your_data&amp;gt;;&lt;/P&gt;&lt;P&gt;keep &amp;amp;names.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Corrected as noted by ballardw &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 21:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30467#M5807</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-03-13T21:59:09Z</dc:date>
    </item>
    <item>
      <title>Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30468#M5808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza forgot to include the input dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data new_data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;lt;yourdataset&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep &amp;amp;names;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 22:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30468#M5808</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-03-13T22:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30469#M5809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;Note : Do not use the period character in SAS dataset names. That's just asking for trouble.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a_data;&lt;BR /&gt;input id var1 var2 var3 var4 var5 var6 var7;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 1 1 0 1 0 1 1 &lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a_vars;&lt;BR /&gt;input var $;&lt;BR /&gt;datalines;&lt;BR /&gt;var1&lt;BR /&gt;var2&lt;BR /&gt;var3&lt;BR /&gt;var6&lt;BR /&gt;var7&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select var into :varList separated by " " from a_vars;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(keep=&amp;amp;varList); set a_data; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 22:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30469#M5809</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-03-13T22:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30470#M5810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You'd get at least a warning message in your log with this method, as not all variables might be in the dataset. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 22:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30470#M5810</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-03-13T22:13:09Z</dc:date>
    </item>
    <item>
      <title>Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30471#M5811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you for your replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;proc sql;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;*get columns in your dataset;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table vnames as&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;select name from dictionary.columns&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;where libname=your_libname and memname=yourdataset;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;do i have to select the variable names in this statement?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 22:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30471#M5811</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2012-03-13T22:28:48Z</dc:date>
    </item>
    <item>
      <title>Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30472#M5812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data foo;&lt;/P&gt;&lt;P&gt; array var[10];&lt;/P&gt;&lt;P&gt; do id=1 to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _n_=1 to dim(var);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; var[_n_]=rand('tabled',.5);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data bar;&lt;/P&gt;&lt;P&gt; input var $;&lt;/P&gt;&lt;P&gt; cards;&lt;/P&gt;&lt;P&gt;var1&lt;/P&gt;&lt;P&gt;var3&lt;/P&gt;&lt;P&gt;var5&lt;/P&gt;&lt;P&gt;var7&lt;/P&gt;&lt;P&gt;var9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt; select b.var into :drops separated by ',' &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; from bar b,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary.columns a&lt;/P&gt;&lt;P&gt;&amp;nbsp; where b.var=a.name;&lt;/P&gt;&lt;P&gt; alter table foo drop column &amp;amp;drops;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 22:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30472#M5812</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2012-03-13T22:35:49Z</dc:date>
    </item>
    <item>
      <title>Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30473#M5813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are sure that every variable named in A.VARS actually appears in&amp;nbsp; A.DATA, here is the method I like.&amp;nbsp; This assumes that VARNAME is the name of the one and only variable in A.VARS:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('data new.data; set a.data (keep=');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (done);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a.vars end=done;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(varname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('); run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The log will show you the statements that get generated.&amp;nbsp; Also, note that ID will be dropped if it is not named in A.VARS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 22:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30473#M5813</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-03-13T22:50:24Z</dc:date>
    </item>
    <item>
      <title>Process to remove variables from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30474#M5814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, it grabs the names of the variables in your dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You only need to specify the library and dataset name in the where clause. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then the dataset to pull the the names you want to keep in the next query. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Mar 2012 23:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Process-to-remove-variables-from-another-dataset/m-p/30474#M5814</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-03-13T23:41:55Z</dc:date>
    </item>
  </channel>
</rss>

