BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
afiqcjohari
Quartz | Level 8

 

data want;
	set have;
	where dTran >= '01JAN2017'd
		and dTran <= '31JAN2017'd 
		and cPOSMode in ('07') 
	    or (dTran >= '01JAN2017'd
	        and dTran <= '31JAN2017'd 
                and cPOSMode in ('90','02') 
	        and cToken is not null 
		and cPvder is not null 
		and idTReq is not null);
run;

Is it possible to simplify the conditions by factoring out the dates?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Maybe

 

data want;
	set have;
	where dTran between '01JAN2017'd and '31JAN2017'd 
		and ( cPOSMode in ('07') 
		     or (cPOSMode in ('90','02') 
	             and cmiss(cToken, cPvder, idTReq) = 0) );
run;

/* Or */

data want;
	set have;
	where year(dTran) = 2017 
		and ( cPOSMode in ('07') 
		     or (cPOSMode in ('90','02') 
	             and cmiss(cToken, cPvder, idTReq) = 0) );
run;
PG

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

Logical algebra:

 

A and B or A and C is equivalent to A and (B or C)

PG
afiqcjohari
Quartz | Level 8
data want;
	set have;
	where dTran >= '01JAN2017'd and dTran <= '31JAN2017'd 
		and (cPOSMode in ('07') 
		     or (cPOSMode in ('90','02') 
	             and cToken is not null 
		         and cPvder is not null 
		         and idTReq is not null));
run;

Hurm not sure whether it looks more readable. 

PGStats
Opal | Level 21

Maybe

 

data want;
	set have;
	where dTran between '01JAN2017'd and '31JAN2017'd 
		and ( cPOSMode in ('07') 
		     or (cPOSMode in ('90','02') 
	             and cmiss(cToken, cPvder, idTReq) = 0) );
run;

/* Or */

data want;
	set have;
	where year(dTran) = 2017 
		and ( cPOSMode in ('07') 
		     or (cPOSMode in ('90','02') 
	             and cmiss(cToken, cPvder, idTReq) = 0) );
run;
PG
afiqcjohari
Quartz | Level 8
That cmiss function does help! Thank you PG!
afiqcjohari
Quartz | Level 8
cmiss routine not found. Is it not part of SAS base or something?
PGStats
Opal | Level 21

Looking at historical doc, cmiss was introduced in base SAS in version 9.2

 

In what context and with what version of SAS are you calling cmiss?

PG
afiqcjohari
Quartz | Level 8
I just figured out that the server is running a 9.1 version while my desktop is on 9.3

This explains why I can run the function previously.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 863 views
  • 2 likes
  • 2 in conversation