BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BonnaryW
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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();

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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();

BonnaryW
Obsidian | Level 7
Thank you for your response and offer the solution Astounding.
ChrisNZ
Tourmaline | Level 20

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 875 views
  • 0 likes
  • 3 in conversation