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?
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;
Logical algebra:
A and B or A and C is equivalent to A and (B or C)
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.
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;
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?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.