BookmarkSubscribeRSS Feed
Kiteulf
Quartz | Level 8

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 ;


;

2 REPLIES 2
ballardw
Super User

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.

Astounding
PROC Star

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

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


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
  • 1009 views
  • 0 likes
  • 3 in conversation