I have this code: which generates missing months between dates. eg:
However I want to force the the second current month, which today will be July.
| 1 | id | Char | 200 | |
| 2 | date | Num | 8 | YYMMN6. |
| 3 | _TYPE_ | Num | 8 | |
| 4 | _FREQ_ | Num | 8 | |
| 5 | spend | Num | 8 |
INPUT ID $200. date yymmn6. _TYPE_ 8. _FREQ_ 8. spend 8.;
Datalines;
2572294 201202 3 1 1
2572294 201210 3 1 1
2572294 201211 3 1 1
2572294 201307 3 1 1
2572294 201312 3 1 1
2572294 201404 3 1 1
2572294 201405 3 1 1;
run;
summary nway data= utsett99( keep= id spend date ) ;
class id date ;
var spend ;
output sum= out= summary1 ;
;
monthly_data ;* add rows for months with no spend ;
set summary1 ;
by id ;
if first.id then priordate= date ;
output ;
. ;
do while( intck( 'month', date, target) > 1) ;
'month', date, 1) ;
output ;
end ;
keep id spend date ;
;
It might help to show us what you expect for output. And your posted code has lots of stuff missing so can't really comment on that either. You may need to paste into a plain text editor such as Notepad before copy and paste to this site.
Getting the month prior to the current month is relatively easy. What am I missing?
prior_month = intnx('month', today(), -1);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.