f



Re: How to filter sas data sets into separate sas data sets #3

Lizette,

Instead of trying to merge the two data sets, I would probably try to create
a SAS format from the values of VAR1 in data set 1.  Then, NODE1, NODE2 and
NODE3 could be compared against the format for a match.

The example below is a simplified version of what you could do and shows a
printout of how it works.  It has 5 observations in data set 1 and only 3
variables in data set 2, but I think the logic should hold for the example
you gave.  After the example is code that could be used to actually split
the data as you had requested.  Hope this helps.


* create sas data set 1 ;
data sasds1;
   input var1 $;
cards;
AAA
BBB
DDD
FFF
AAA
HHH
;
run;

* sort data set 1 to eliminate any duplicate values ;
proc sort nodupkey data = sasds1 out = sasds1_dd (rename=(var1=start));
   by var1;
run;

* create data set that will be used to build SAS format ;
data sasds1_dd;
   set sasds1_dd end=last;
fmtname = '$NODES';
label = 'Y';
output;
if last then do;
   hlo='O';
   label='N';
   output;
end;
run;

* build format (the optional fmtlib option will print the format for you to
review) ;
proc format cntlin = sasds1_dd fmtlib;
run;

* create sas dataset 2 ;
data sasds2;
   input node1 $ node2 $ node3 $;
cards;
ZZZ YYY XXX
AAA YYY XXX
ZZZ FFF XXX
ZZZ YYY DDD
AA  YYY XXX
ZZZ AAAA XXX
;
run;

* apply format to node1-node3 to determine if there is a match ;
data testing;
   set sasds2;
if put(node1,$nodes.) = 'Y' or
   put(node2,$nodes.) = 'Y' or
   put(node3,$nodes.) = 'Y' then keep_it='Y';
        else keep_it = 'N';
run;

proc print data = testing;
run;


Once you review this example, if it seems to do what you want, the splitting
of the data could be accomplished with the code below.


data newlist otherds;
   set sasds2;
if put(node1,$nodes.) = 'Y' or
   put(node2,$nodes.) = 'Y' or
   put(node3,$nodes.) = 'Y' then output newlist;
        else output otherds;
run;



Jack Clark
Research Analyst
Center for Health Program Development and Management
University of Maryland, Baltimore County




-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Lizette
Koehler
Sent: Monday, April 02, 2007 10:53 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: How to filter sas data sets into separate sas data sets

Listers,

This is my failing point in coding SAS.  The use of 2 separate SAS data sets
to create a third.

I can do this in a program with nested Do loops.  But with SAS it is just
different enough I seem to be unable to see the coding technique.

Problem:

Sas Data set 1 contains 1 variable and 1000 obs.
Sas Data set 2 contains 15 variables and 500000 obs.

I need to filter off the data in Sas data set 2 based on Sas data set 1

Node1, Node2 and Node3 must match VAR1 exactly.  I have all the code I need
to do this except for splitting the data into a separate SAS data set
(NEWLISTS).


Psuedo code:

Sas Data set 1:  Var1 Length 7 Char
Sas Data set 2:  Node1 Length 1-8 Char   Node2 Length 1-8 Char  Node3 Length
1-8 Char



Data Newlist (KEEP=node1 node2 node3 ... var15)
     Otherds (Keep=node1 node2 node3 .... var15) ;

Set SASDS1 ;   *Contains 1 var 1000 obs   ;
Set SASDS2 ;   *Contains 15 vars and 500,000 obs  ;


If Node1 = VAR1 or Node2 = VAR1 or Node3 = Var1 then Output Newlist ;
Else Output Otherds ;


I have tried putting in two SET statements, but I seem to reduce the
information dramatically.  I have been reviewing the coding examples on the
SAS Wesbsite as well as in the archives.  I am just so crunched for time
that I must lean on you for assistance.

I know this should be easy, I am just not seeing.

Thanks for the assistance

Lizette
0
JClark1 (431)
4/2/2007 3:24:34 PM
comp.soft-sys.sas 142827 articles. 4 followers. Post Follow

0 Replies
1360 Views

Similar Articles

[PageSpeed] 36

Reply: