BookmarkSubscribeRSS Feed
Mick_lb
Calcite | Level 5

Hello everyone,

 

I want to increment a value from the number 13.

In my case, the number 13 means "September2017".

I want to increment this number by 1 for each additional month (14 for October2017, 15 for November2017, 16 for December2017, 17 for January2018 and so on...).

 

For example, if I want the number 14, I tried the following code :

 

 

%let Initial_Month='01SEP2017'd; /*Fixed value*/
%let Day=%sysfunc(intnx(month, %sysfunc(today()), -1), DATE9.);
%let Actual_Month= 13 + %sysfunc(intck('month', &Initial_Month. , &Day.));

 

 

But I got the following error :

ERROR: Argument 3 to function INTCK referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.

 

I'm also opened to solutions using Data steps, the point is just to get a macro variable with an autoincremental value 14.

 

Thank you in advance for your help !

 

Best regards,

1 REPLY 1
PaigeMiller
Diamond | Level 26

A common mistake is that you have formatted a macro variable into a human-readable date. DO NOT FORMAT MACRO VARIABLE VALUES into human-readable values (unless you are using these dates in titles or labels).

 

%let Initial_Month='01SEP2017'd; 
%let Day=%sysfunc(intnx(month, %sysfunc(today()),-1)); /* I removed the format here */
%let Actual_Month= %eval(13 + %sysfunc(intck(month, &Initial_Month. , &Day.))); 
%put &=actual_month;

This works because now DAY is an integer representing the number of days since Jan 1 1960; which is how SAS needs to have date values represented. Since I ran this on 12/12/19, the value of &DAY is 21854. This works properly in INTCK. If &DAY is 01NOV2019 (as you would have in your original code), this is not a valid third argument of INTCK.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 249 views
  • 0 likes
  • 2 in conversation