- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
suppose to have the following:
data DB1;
input ID Discharge;
format Discharge date9.;
cards;
0001 19JUN2017
0001 07SEP2020
0002 17MAR2016
0003 05MAY2016
0003 08FEB2017
0004 22MAR2017
0004 03MAY2017
0004 28MAR2021
;
data DB2;
input ID Discharge Flag NewDate;
format Discharge NewDate date9.;
cards;
0001 19JUN2017 0 .
0001 07SEP2020 1 08SEP2020
0002 17MAR2016 1 18MAR2016
0003 05MAY2016 0 .
0003 08FEB2017 1 09FEB2017
0004 22MAR2017 0 .
0004 03MAY2017 0 .
0004 28MAR2021 1 29MAR2021
;
Is there a way to add a flag to DB1 where for each ID there's the latest date (if there is only one date as for ID 0002 the last date will be the one reported) and then add the new date corresponding to the last + 1 day? Desired output: DB2.
Thank you in advance
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set db1;
by id;
flag=0;
if last.id then do;
newdate=discharge + 1;
flag=1;
end;
format newdate date9.;
run;
The above assumes that DISCHARGE is an actual valid SAS date value. In the code you provided, it is not an actual valid SAS date value, and so you need to fix the code for DB1.
PS: when you provide data as SAS data step code, please test it before you provide it to make sure it works. The code does not work as intended, making all values of DISCHARGE missing.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set db1;
by id;
flag=0;
if last.id then do;
newdate=discharge + 1;
flag=1;
end;
format newdate date9.;
run;
The above assumes that DISCHARGE is an actual valid SAS date value. In the code you provided, it is not an actual valid SAS date value, and so you need to fix the code for DB1.
PS: when you provide data as SAS data step code, please test it before you provide it to make sure it works. The code does not work as intended, making all values of DISCHARGE missing.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@NewUsrStat wrote:
Seems to be impossible to edit. No "edit" bottom appears.
Unless "bottom" is misspelled "button" this doesn't make sense. The three horizontal line icon next to the subject line of your post should have an "edit" option in the drop down menu when clicked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@NewUsrStat wrote:
Seems to be impossible to edit. No "edit" bottom appears.
After some time posts get locked and you can't edit them anymore. Just provide an answer to your own question with the updated code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Edit to the code to allow it working correctly:
data DB1;
input ID :$20.Discharge :date9.;
format Discharge date9.;
cards;
0001 19JUN2017
0001 07SEP2020
0002 17MAR2016
0003 05MAY2016
0003 08FEB2017
0004 22MAR2017
0004 03MAY2017
0004 28MAR2021
;
data DB2;
input ID :$20. Discharge :date9. Flag :$20. NewDate:date9.;
format Discharge NewDate date9.;
cards;
0001 19JUN2017 0 .
0001 07SEP2020 1 08SEP2020
0002 17MAR2016 1 18MAR2016
0003 05MAY2016 0 .
0003 08FEB2017 1 09FEB2017
0004 22MAR2017 0 .
0004 03MAY2017 0 .
0004 28MAR2021 1 29MAR2021
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Looks like @PaigeMiller already provided the code that returns your desired result. Suggest you mark it as the solution.