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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 834 views
  • 2 likes
  • 2 in conversation