<?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: Subset using proc contents output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420737#M103537</link>
    <description>&lt;P&gt;It is easier to use&amp;nbsp;dictionary.columns to get the common variables:&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
  select name into :dropvars separated by ' '
  from dictionary.columns
  where libname='SASHELP' and memname='CARS'
   and name in(select name from dictionary.columns where libname='SASHELP' and memname='CLASS');
  ;
quit;

data class_without_cars;
  set sashelp.class(drop=&amp;amp;dropvars);
run;&lt;/PRE&gt;&lt;P&gt;This will drop the variable WEIGHT, which is common&amp;nbsp;to the two datasets.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Dec 2017 11:03:34 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2017-12-13T11:03:34Z</dc:date>
    <item>
      <title>Subset using proc contents output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420441#M103473</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to subset a data set based on the proc contents output. For e.g. I want to exclude all those variables which are a part of another data set .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 12:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420441#M103473</guid>
      <dc:creator>Lopa2016</dc:creator>
      <dc:date>2017-12-12T12:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subset using proc contents output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420448#M103474</link>
      <description>&lt;P&gt;Retrieve meta-information about datasets from dictionary.tables (SQL) or sashelp.vtable (data step). This will then help you in creating macro variables for use in drop or keep statements.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 12:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420448#M103474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-12T12:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Subset using proc contents output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420449#M103475</link>
      <description>&lt;P&gt;If you insist on using PROC CONTENTS output then do like below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, i agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, get the information from dictionary tables or&amp;nbsp;&lt;SPAN&gt;sashelp.vtable&lt;/SPAN&gt; instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents noprint data=sashelp.heart out=VarsToDrop(keep=name);
run;

proc sql noprint;
	select name into :vars separated by ' '
	from VarsToDrop;
quit;

%put &amp;amp;vars.;

data ClassExludingVars;
	set sashelp.class;
	drop &amp;amp;vars.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 13:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420449#M103475</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-12T13:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Subset using proc contents output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420465#M103482</link>
      <description>&lt;P&gt;Let's say you want all the variables in B that are not also in A:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bvars_only;
  retain _sentinel1;
  if 0 then set a;
  retain _sentinel2;
  set b;
  drop _sentinel1--_sentinel2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This relies on how SAS constructs the program data vector. This program orders variables in the PDV&amp;nbsp;from left to right as&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;_sentinel1&lt;/LI&gt;
&lt;LI&gt;all the A vars&lt;/LI&gt;
&lt;LI&gt;_sentinel2&lt;/LI&gt;
&lt;LI&gt;all the B vars not already&amp;nbsp;in item2 above.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The drop statement, using a double-dash connector tells SAS to drop all the vars in item1, item2, and item3.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 14:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420465#M103482</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-12T14:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Subset using proc contents output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420471#M103484</link>
      <description>&lt;P&gt;Let's say you want to drop variables in B which also appear in A.&amp;nbsp; You could start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=A noprint out=contents_A (keep=name);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc contents data=B noprint out=contents_B (keep=name);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the issues are (1) finding variable names that appear in both, despite the fact that (2) capitalization of the names can be different in both data sets.&amp;nbsp; So:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data contents_A;&lt;/P&gt;
&lt;P&gt;set contents_A;&lt;/P&gt;
&lt;P&gt;name = upcase(name);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=contents_A;&lt;/P&gt;
&lt;P&gt;by name;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data contents_B;&lt;/P&gt;
&lt;P&gt;set contents_B;&lt;/P&gt;
&lt;P&gt;name = upcase(name);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=contents_B;&lt;/P&gt;
&lt;P&gt;by name;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having a list of variable names from both sources (capitalized and sorted), the next step is to find those names appear in both:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data matching;&lt;/P&gt;
&lt;P&gt;merge contents_A (in=ina) contents_B (in=inb);&lt;/P&gt;
&lt;P&gt;by name;&lt;/P&gt;
&lt;P&gt;if ina and inb;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having found the matches, extract the names into a macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select name into : matching_vars separated by ' ' from matching;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, drop the variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set a (drop=&amp;amp;matching_vars);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, it takes a long series of steps (at least the way that I'm picturing the problem requires many steps).&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 14:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420471#M103484</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-12T14:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Subset using proc contents output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420737#M103537</link>
      <description>&lt;P&gt;It is easier to use&amp;nbsp;dictionary.columns to get the common variables:&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
  select name into :dropvars separated by ' '
  from dictionary.columns
  where libname='SASHELP' and memname='CARS'
   and name in(select name from dictionary.columns where libname='SASHELP' and memname='CLASS');
  ;
quit;

data class_without_cars;
  set sashelp.class(drop=&amp;amp;dropvars);
run;&lt;/PRE&gt;&lt;P&gt;This will drop the variable WEIGHT, which is common&amp;nbsp;to the two datasets.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 11:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-using-proc-contents-output/m-p/420737#M103537</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-12-13T11:03:34Z</dc:date>
    </item>
  </channel>
</rss>

