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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
 set ONE TWO;
 where '01JAN2015'd <= coalesce(from_dt,thru_dt) <= '05JAN2015'd ;

run;

View solution in original post

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
 set ONE TWO;
 where '01JAN2015'd <= coalesce(from_dt,thru_dt) <= '05JAN2015'd ;

run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 698 views
  • 0 likes
  • 2 in conversation