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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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