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

How to replace the "missing value ." between 2000/01/02 and 2000/02/15 with the value "5" on 2000/01/01?

 

ID     DATE           Variable

01   2000/01/01         5

01   2000/01/02         .

01   2000/01/03         .

01   2000/01/04         .

01   2000/01/05         .

.................

01   2000/02/15         .

01   2000/02/16         7

 

Assuming that there are many ID like '01' and many case like missing value between 2000/01/02 and 2000/02/15. Is there any efficient way to replace these missing value with the most recently available value like '5' in this case before new value like '7' is available?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
input ID$ DATE:yymmdd10. Variable;
format DATE yymmdd10.;
datalines;
01 2000/01/01 5
01 2000/01/02 .
01 2000/01/03 .
01 2000/01/04 .
01 2000/01/05 .
01 2000/02/15 .
01 2000/02/16 7
;

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

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data have;
input ID$ DATE:yymmdd10. Variable;
format DATE yymmdd10.;
datalines;
01 2000/01/01 5
01 2000/01/02 .
01 2000/01/03 .
01 2000/01/04 .
01 2000/01/05 .
01 2000/02/15 .
01 2000/02/16 7
;

data want;
   update have(obs=0) have;
   by ID;
   output;
run;
mkeintz
PROC Star

You'll find the answer to the antecedent to this topic in How to merge daily and quarterly dataset

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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