Hi expert,
I had several datasets. Some datasets only contains thru_dt, and some datasets contains both from_dt and thru_dt. I wanted to select
a). if the dataset only contains thru_dt, then select '01JAN2015'd <=thru_dt<='05JAN2015'd,
b). if the dataset contains both from_dt and thru_dt, then select '01JAN2015'd <=from_dt<='05JAN2015'd.
For example:
data one;
input id $ thru_dt:mmddyy10.;
format thru_dt mmddyy10.;
datalines;
1 01/01/2015
2 01/02/2015
3 01/03/2015
4 01/04/2015
5 01/05/2015
6 01/06/2015
7 01/07/2015
;
run;
data two;
input id $ from_dt:mmddyy10. thru_dt:mmddyy10.;
format from_dt thru_dt mmddyy10.;
datalines;
1 01/01/2015 01/02/2015
2 01/02/2015 01/03/2015
3 01/03/2015 01/03/2015
4 01/04/2015 01/04/2015
5 01/05/2015 01/05/2015
6 01/06/2015 01/06/2015
7 01/07/2015 01/07/2015
;
run;
I tried the following codes, but it said ERROR: Variable from_dt is not on file WORK.ONE.
data want;
set one two;
where '01JAN2015'd <=from_dt<='05JAN2015'd | '01JAN2015'd <=thru_dt<='05JAN2015'd;
run;
Any suggestions would be greatly appreciated!
Like this?
data WANT;
set ONE TWO;
where '01JAN2015'd <= coalesce(from_dt,thru_dt) <= '05JAN2015'd ;
run;
Like this?
data WANT;
set ONE TWO;
where '01JAN2015'd <= coalesce(from_dt,thru_dt) <= '05JAN2015'd ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.