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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3388 views
  • 1 like
  • 3 in conversation