BookmarkSubscribeRSS Feed
lillymaginta
Lapis Lazuli | Level 10
data have;
input id start_Dt dx_dt end_dt qt;
format start_Dt dx_dt end_dt mmddyy10.;
cards;
1  1/1/2005 1/2/2005  2/2/2005  30
2  3/3/2005 3/4/2005  9/10/2005  5
2  1/4/2006 4/4/2006 5/8/2006   10
2  5/1/2007 5/5/2007 5/7/2007   15
;
run;

I have the following data. I need to retain any observation were the time between dx_Dt and end_dt is within 7 days of start_dt and keep the qt variable in the output dataset

Output data

1  1/2/2005  1/9/2005  30

2  3/4/2005  3/10/2005 5

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Why is this row not included in the output?

 

2  5/1/2007 5/5/2007 5/7/2007   15

 

 

--
Paige Miller
lillymaginta
Lapis Lazuli | Level 10

Sorry Paige, I meant and so on. I just wanted to give an example of the output for the first two. 

PaigeMiller
Diamond | Level 26

Well, if I am understanding the request properly, then this should work (note: there is no data set named WANT produced, all of this is done when creating data set HAVE)

 

data have;
input id start_Dt dx_dt end_dt qt;
if dx_dt-start_dt<=7 or end_dt-start_dt<=7 then output;
informat start_Dt dx_dt end_dt mmddyy10.;
format start_Dt dx_dt end_dt mmddyy10.;
cards;
1  1/1/2005 1/2/2005  2/2/2005  30
2  3/3/2005 3/4/2005  9/10/2005  5
2  1/4/2006 4/4/2006 5/8/2006   10
2  5/1/2007 5/5/2007 5/7/2007   15
;
run;

 

 

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 3 replies
  • 1014 views
  • 0 likes
  • 2 in conversation