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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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