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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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