DATA Step, Macro, Functions and more

How to use where if in data step?

Reply
Frequent Contributor
Posts: 99

How to use where if in data step?

	data want1;
		set have;
		where cPOSMode in ('07','90');
	run;
	data want2;
		set have;
		where cPOSMode in ('02') 
			and cToken is not null
			and cPvder is not null
			and idTReq is not null;
	run;
       
        data want1; set want1 want2;run;

How do I simplify above 3 data steps into 1?

Super User
Posts: 19,772

Re: How to use where if in data step?

Posted in reply to afiqcjohari

Combine WHERE clauses into 1 step using an OR

Frequent Contributor
Posts: 99

Re: How to use where if in data step?

data want;
set have;
where cPOSMode in ('07','90') or (cPOSMode in ('02') and cToken is not null and cPvder is not null and idTReq is not null);
;run;
Super User
Posts: 19,772

Re: How to use where if in data step?

Posted in reply to afiqcjohari

afiqcjohari wrote:
data want;
set have;
where cPOSMode in ('07','90') or (cPOSMode in ('02') and cToken is not null and cPvder is not null and idTReq is not null);
;run;

Super User
Super User
Posts: 7,942

Re: How to use where if in data step?

Posted in reply to afiqcjohari
data want;
  set have;
  if cposmode in ('07','90') or
     cposmode='02 and (ctoken ne "" and cpvder ne "" and idtreq ne "") then output;
run; 

Note, I assume the three varaibles are character as you don't say.  Also, use one casing for your code, mixing casing makes code harder to read.

Ask a Question
Discussion stats
  • 4 replies
  • 120 views
  • 0 likes
  • 3 in conversation