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(,)
What exactly is the result supposed to be?
You may be wanting to use %sysfunc as %eval only works for integer arithmetic.
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.
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*/
Try % substr.
<forehead pop>
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!
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.