DATA Step, Macro, Functions and more

Macro Variable

Reply
Frequent Contributor
Posts: 126

Macro Variable

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

Super User
Posts: 11,343

Re: Macro Variable

What exactly is the result supposed to be?

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

Frequent Contributor
Posts: 126

Re: Macro Variable

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.

Super User
Posts: 11,343

Re: Macro Variable

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*/

Super User
Posts: 5,431

Re: Macro Variable

Try % substr.

Data never sleeps
Super User
Posts: 11,343

Re: Macro Variable

<forehead pop>

Ask a Question
Discussion stats
  • 5 replies
  • 466 views
  • 0 likes
  • 3 in conversation