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>
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.