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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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