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

Hi, I have day-by-day data where some dates are missing. I would like to add missing dates to a new row and assign them a value of 0 in a separate column. There are no duplicates in the data, and they are sorted from oldest to newest. It looks like below:

data have;
input date :yymmdd10. count;
format date yymmddd10.;
datalines;
2022-03-02 20
2022-03-03 24
2022-03-05 23
2022-03-07 15
;
run;
data want;
input date :yymmdd10. count;
format date yymmddd10.;
datalines;
2022-03-02 20
2022-03-03 24
2022-03-04 0
2022-03-05 23
2022-03-06 0
2022-03-07 15
;
run;

Do you know an easy way to quickly complete such a table?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If so then Proc Timeseries is the right tool

 

data have;
input date :yymmdd10. count;
format date yymmddd10.;
datalines;
2022-03-02 20
2022-03-03 24
2022-03-05 23
2022-03-07 15
;
run;

proc timeseries data = have out = want;
   id date interval   = day
           accumulate = none
           setmiss    = 0
           format     = yymmddd10.;
   var count;
run;

 

Result:

 

date        count 
2022-03-02  20 
2022-03-03  24 
2022-03-04  0 
2022-03-05  23 
2022-03-06  0 
2022-03-07  15  

 

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

If so then Proc Timeseries is the right tool

 

data have;
input date :yymmdd10. count;
format date yymmddd10.;
datalines;
2022-03-02 20
2022-03-03 24
2022-03-05 23
2022-03-07 15
;
run;

proc timeseries data = have out = want;
   id date interval   = day
           accumulate = none
           setmiss    = 0
           format     = yymmddd10.;
   var count;
run;

 

Result:

 

date        count 
2022-03-02  20 
2022-03-03  24 
2022-03-04  0 
2022-03-05  23 
2022-03-06  0 
2022-03-07  15  

 

PatrykSAS
Obsidian | Level 7
This code did its job. Thanks for the help!
Ksharp
Super User
data have;
input date :yymmdd10. count;
format date yymmddd10.;
datalines;
2022-03-02 20
2022-03-03 24
2022-03-05 23
2022-03-07 15
;
run;

data want;
merge have have(keep=date rename=(date=_date) firstobs=2);
output;
do date=date+1 to coalesce(_date-1,0);
 count=0;output;
end;
drop _date;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 2421 views
  • 1 like
  • 3 in conversation