DATA Step, Macro, Functions and more

Increase months to current month

Reply
Contributor
Posts: 40

Increase months to current month

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.

1idChar200
2dateNum8YYMMN6.
3_TYPE_Num8
4_FREQ_Num8
5spendNum8

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 ;


;

Super User
Posts: 11,343

Re: Increase months to current month

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.

Super User
Posts: 5,513

Re: Increase months to current month

Getting the month prior to the current month is relatively easy.  What am I missing?

prior_month = intnx('month', today(), -1);


Ask a Question
Discussion stats
  • 2 replies
  • 279 views
  • 0 likes
  • 3 in conversation