BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

data s1 ;
input id $ start_date:date9. end_date:date9. ;
format start_date end_date date9. ;
cards ;
101 23sep2018  24sep2018
101 25sep2018  27sep2018
101 .                  30sep2018
101 02oct2018  04oct2018
101 .                  08sep2018
;

Q1)in above dataset start_date has some missing values then how to assign previous values of end_date variable?

id

start_date

end_date

101

23SEP2018

24SEP2018

101

25SEP2018

27SEP2018

101

27SEP2018

30SEP2018

101

02OCT2018

04OCT2018

101

04OCT2018

08SEP2018

Q2)in above dataset start_date has some missing values then how to assign previous values of end_date variable and add one day see below dataset?

id

start_date

end_date

101

23SEP2018

24SEP2018

101

25SEP2018

27SEP2018

101

28SEP2018

30SEP2018

101

02OCT2018

04OCT2018

101

05OCT2018

08SEP2018

 

2 REPLIES 2
Astounding
PROC Star

data want;

set have;

by id;

prior_end = lag(end_date);

if start_date = . and first.id = 0 then do;

   * For Q1;

   start_date = prior_end;

   * For Q2;

   start_date = prior_end + 1;

end;

drop prior_end;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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