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
Why is this row not included in the output?
2 5/1/2007 5/5/2007 5/7/2007 15
Sorry Paige, I meant and so on. I just wanted to give an example of the output for the first two.
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;
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!
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.