Hello,
I am not sure if this is the right way of doing it. I would like to add month and year to the title based on what month it is. I need to add one year, if month is January, February, and March, otherwise leave year as the current year. Below is my codes.
%let today = %sysfunc(today());
%let pmo1= %sysfunc(putn(%sysfunc(intnx(month,&today,+3)),monname));
%let pmo2= %sysfunc(putn(%sysfunc(intnx(month,&today,+5)),monname));
IF &pmo1 IN ("January","February","March") OR &pmo2 in ("January","February","March") THEN
%let OCYR= %SYSFUNC(year(%SYSFUNC(INTNX(year,&today,+1))));
ELSE
%let OCYR= %sysfunc(year(&today));
title1 "Testing &pmo1 &ocyr &pmo2 &ocyr";
Result:
Testing November 2018 January 2019.
Thank you.
Second chance:
You will find this much easier if you just use a DATA step to compute the values. Then use CALL SYMPUTX to transfer the DATA step values to macro variables.
Certainly you will need two YEAR variabels. You can't refer to the same macro variable in two spots and have it switch from 2018 to 2019.
So start with:
data _null_;
today = today();
Second chance:
You will find this much easier if you just use a DATA step to compute the values. Then use CALL SYMPUTX to transfer the DATA step values to macro variables.
Certainly you will need two YEAR variabels. You can't refer to the same macro variable in two spots and have it switch from 2018 to 2019.
So start with:
data _null_;
today = today();
This code is totally invalid.
IF &pmo1 IN ("January","February","March") OR &pmo2 in ("January","February","March") THEN %let OCYR= %SYSFUNC(year(%SYSFUNC(INTNX(year,&today,+1))));
ELSE %let OCYR= %sysfunc(year(&today));
1. %let cannot be controlled by if then
2. macro variable pmo1 contains no quotes
This shows a lack of understanding of the basic concepts.
As @Astounding said, stick to a data step. You can use the macro language when your SAS skills are more advanced.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.