1. You need SAS dates for using INTNX. Don’t separate it to year and Month components.
2. You don’t need SYSFUNC within a data step
3. For previous month and year, that’s 13 months ago. Try using Month and -13 in INTNX.
4. Please format and comment your code. Formatting makes it easier to read, commenting shows your logic or what you expect so we can help.
5. Use the format YYMMN6 to get the dates you want
Did you try INTNX()?
@sayanapex06 wrote:
Hi everyone,
I need to find the syntax for sas (year-month)
Suppose I code :
Curr = put(today, mmyyd.) ;
I will be getting
Curr = 02-2018
Now my question is,
I need from the sas date function
Curr01 = 12-2017
Curr02 = 11-2017
Curr01 being the previous month and year
Curr02 beung the previous of the previous month
Could you please help me with this function, so that even if I am in the middle of the year, I can get a month - 1 and month - 2 with a single code?
Thanks,
Sayan
@sayanapex06 a simple google search will give you tons of syntax, examples, scenarios. Why be so dependent to ask for syntax help and so on. Personally, I think it is not fair. Anyway, up to you!
@sayanapex06 wrote:
So the current date is 05FEB2018
what will happen if I use this
Curr02 = intx('month', currd, -2)
What will be the value of curr02?
Run it and see....
I coded the following :
DATA TEST ;
C_MONTH = MONTH(TODAY()) ;
C_YEAR = YEAR(TODAY()) ;
P_MONTH =%SYSFUNC(MONTH(%SYSFUNC(INTNX(MONTH, %SYSFUNC(TODAY()), -1))));
P_YEAR =%SYSFUNC(YEAR(%SYSFUNC(INTNX(MONTH, %SYSFUNC(TODAY()), -1))));
PROC PRINT DATA = TEST ;
got the output as :
C_MONTH C_YEAR P_MONTH P_YEAR
2 2018 1 2018
Now what to do if I want a P_P_MONTH (previous of the previous month) and P_P_YEAR
P_P_MONTH has to be 12
P_P_YEAR has to be 2017
Please help me with the above
1. You need SAS dates for using INTNX. Don’t separate it to year and Month components.
2. You don’t need SYSFUNC within a data step
3. For previous month and year, that’s 13 months ago. Try using Month and -13 in INTNX.
4. Please format and comment your code. Formatting makes it easier to read, commenting shows your logic or what you expect so we can help.
5. Use the format YYMMN6 to get the dates you want
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.