BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TheNovice
Quartz | Level 8

I have received a dataset like below:

Dataset is sorted by Cal_date but the rows are blank after the first row is populated. I am trying to populate the remaining rows with the previous date... until the next date starts...

Cal DateResource Name
01/02/2019B
.B
.B
01/03/2019B

 

I put a variable flag = 0 where cal_date = . but i am stuck

I am trying below but not working... any direction would be appreciated


data want;
 set test;
 format newdate date9.;
      retain lag_date;
      lag_date = cal_date;
 
     if flag =1 then newdate = lag_date;
     drop lag_date;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input (Cal_Date	Resource_Name) (:$10.);
cards;
01/02/2019	B
.	D
.	C
01/03/2019	E
.	E
;

data want;
 set have;
 retain _date;
 if not missing(Cal_Date) then _date=cal_date;
 else cal_date=_date;
 drop _date;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

data have;
input (Cal_Date	Resource_Name) (:$10.);
cards;
01/02/2019	B
.	B
.	B
01/03/2019	B
;

data want;
 update have(obs=0) have;
 by Resource_Name;
 output;
run;

TheNovice
Quartz | Level 8

Thanks for the quick reply... i think i may have simplified it too much.. the resource_names can be different. I just need the dates to keep populating until the new dates starts

input

Cal DateResource Name
01/02/2019B
.D
.C
01/03/2019E
.E

output needed

 

  
Cal DateResource Name
01/02/2019B
01/02/2019D
01/02/2019C
01/03/2019E
01/03/2019E
novinosrin
Tourmaline | Level 20

data have;
input (Cal_Date	Resource_Name) (:$10.);
cards;
01/02/2019	B
.	D
.	C
01/03/2019	E
.	E
;

data want;
 set have;
 retain _date;
 if not missing(Cal_Date) then _date=cal_date;
 else cal_date=_date;
 drop _date;
run;
TheNovice
Quartz | Level 8
It works.Thank you so much!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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