keeping only certain values of a variable (not manually)

Hi there,

I have two data sets. One is a large data set containing a week variable 'wk'. The other has just one variable , 'wk2', which contains values of 'wk' corresponding to rows in the large data set that I'd like to keep, and remove the rest.

How can I do this? (without manually listing the weeks)

My idea is to merge the two sets, then use a where statement to only keep data where 'wk' is an element of 'wk2' but I cannot find any syntax for something like this.

I'd really appreciate any help. Thanks!

Mean Joe

TS Contributor
Use the SAS IN= function. Should also rename wk2=wk.

data justone; set justone; rename wk2=wk; run;
proc sort data=justone nodupkey; by wk; run;

proc sort data=largedata; by wk; run;

data large_trim;
merge largedata(in=a) justone(in=b);
by wk;
if a and b; *You'll only keep the records where WK in 'largedata' also appears in 'justone';

Note that the temporary variables a and b created for the IN= function, are only temporary.