<?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: Keeping Variables based on some condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66442#M14415</link>
    <description>You can read B, and based on the information there, create a macro variable (CALL SYMPUT) that contains a KEEP list which can be used when reading A in the next step.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
    <pubDate>Thu, 18 Dec 2008 08:49:04 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2008-12-18T08:49:04Z</dc:date>
    <item>
      <title>Keeping Variables based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66441#M14414</link>
      <description>Here is my problem&lt;BR /&gt;
&lt;BR /&gt;
I have two data sets (A and B)&lt;BR /&gt;
&lt;BR /&gt;
A contains 10 variables and 50 observations.&lt;BR /&gt;
B contains information about some (not all) variables of A.&lt;BR /&gt;
Say in this case B has 8 variables, (all of them are in A too) and only 1 observation, which say 'Y' if that particular variable is to be used into analysis otherwise 'N'.&lt;BR /&gt;
&lt;BR /&gt;
I need to make a final Data set, which has variable which can be used in analysis which all observations from dataset A.&lt;BR /&gt;
&lt;BR /&gt;
Any Guidance?&lt;BR /&gt;
Thanks</description>
      <pubDate>Thu, 18 Dec 2008 08:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66441#M14414</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-12-18T08:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Variables based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66442#M14415</link>
      <description>You can read B, and based on the information there, create a macro variable (CALL SYMPUT) that contains a KEEP list which can be used when reading A in the next step.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 18 Dec 2008 08:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66442#M14415</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-12-18T08:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Variables based on some condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66443#M14416</link>
      <description>I imagine that data A looks like&lt;BR /&gt;
&lt;BR /&gt;
[pre]data A;&lt;BR /&gt;
  input a b c d e f g h i;&lt;BR /&gt;
  datalines;&lt;BR /&gt;
1 2 3 4 5 6 7 8 9&lt;BR /&gt;
9 8 7 6 5 4 3 2 1&lt;BR /&gt;
3 4 5 6 1 2 7 8 9&lt;BR /&gt;
; &lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
From here I have to suggetions based on two different B's - both will result in the same 'new' A called analysis.&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;1)&lt;/B&gt;&lt;/U&gt;[pre]data B;&lt;BR /&gt;
 length var used $1;&lt;BR /&gt;
 input var used;&lt;BR /&gt;
 datalines;&lt;BR /&gt;
B Y&lt;BR /&gt;
C Y&lt;BR /&gt;
F Y&lt;BR /&gt;
A N&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  length _x_ $2000;&lt;BR /&gt;
  retain _x_;&lt;BR /&gt;
  set B(where=(used='Y')) end=last;&lt;BR /&gt;
  _x_ = catx(' ',_x_,var);&lt;BR /&gt;
  if last then call symput('a_vars',strip(_x_));&lt;BR /&gt;
run;&lt;BR /&gt;
%put &amp;amp;a_vars.;&lt;BR /&gt;
&lt;BR /&gt;
data analysis;&lt;BR /&gt;
  set A(keep=&amp;amp;a_vars.);&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;2)&lt;/B&gt;&lt;/U&gt;[pre]data B;&lt;BR /&gt;
 length B C F $1;&lt;BR /&gt;
 input b c f a;&lt;BR /&gt;
 datalines;&lt;BR /&gt;
Y Y Y N&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql NOPRINT;&lt;BR /&gt;
  select name into :varnames SEPARATED by ' '&lt;BR /&gt;
  from sashelp.vcolumn&lt;BR /&gt;
  where libname = 'WORK' and memname = 'B';&lt;BR /&gt;
&lt;BR /&gt;
  select nvar into :nvar&lt;BR /&gt;
  from sashelp.vtable&lt;BR /&gt;
  where libname = 'WORK' and memname = 'INPUT';&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%put &amp;amp;varnames.;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  length x $44 _x_ $2000;&lt;BR /&gt;
  set B;&lt;BR /&gt;
  do i = 1 to &amp;amp;nvar;&lt;BR /&gt;
   x=scan("&amp;amp;varnames",i,' '); &lt;BR /&gt;
   v = vvaluex(x); put v=;&lt;BR /&gt;
   if  v = 'Y' then _x_ = catx(' ',_x_,x);&lt;BR /&gt;
  end;&lt;BR /&gt;
  call symput('a_vars',_x_);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%put &amp;amp;a_vars;&lt;BR /&gt;
&lt;BR /&gt;
data analysis;&lt;BR /&gt;
  set A(keep=&amp;amp;a_vars.);&lt;BR /&gt;
run;[/pre]</description>
      <pubDate>Mon, 22 Dec 2008 22:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Variables-based-on-some-condition/m-p/66443#M14416</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2008-12-22T22:17:32Z</dc:date>
    </item>
  </channel>
</rss>

