BookmarkSubscribeRSS Feed
BTAinRVA
Quartz | Level 8

I'm trying to assign a text string to a macro variable using the code below. I've tried several different ways and none seem to be working. Any help for this macro newbie would be greatly appreciated. Thanks,

StartYr = 2008;

NxtYr=%eval(&StartYr + 1);

Y1Y2 = %eval(cat(%eval(substr("&StartYr",3,2)),%eval(substr("&NxtYr",3,2))));

1454  %Let Y1Y2 = %eval(cat(%eval(substr("&StartYr",3,2)),%eval(substr("&NxtYr",3,2))));

SYMBOLGEN:  Macro variable STARTYR resolves to 2008

ERROR: Required operator not found in expression: substr("2008",3,2)

SYMBOLGEN:  Macro variable NXTYR resolves to 2009

ERROR: Required operator not found in expression: substr("2009",3,2)

ERROR: Required operator not found in expression: cat(,)

5 REPLIES 5
ballardw
Super User

What exactly is the result supposed to be?

You may be wanting to use %sysfunc as %eval only works for integer arithmetic.

BTAinRVA
Quartz | Level 8

Thanks for the reply!

I want Y1Y2 to equal the combined last two characters of StartYr and NxtYr. So if they are 2008 and 2009 I want Y1Y2 to be 0809.

ballardw
Super User

Try

 

%let Y1Y2 = %sysfunc(substr(&StartYr,3,2))%sysfunc(substr(&NxtYr,3,2));

/* note NO space between )%sysfunc */

When I tried using Cat it seems like it wants to resolve the 08 to a numeric 8 loosing the leading 0 and the same with 09*/

LinusH
Tourmaline | Level 20

Try % substr.

Data never sleeps
ballardw
Super User

<forehead pop>

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1524 views
  • 0 likes
  • 3 in conversation