BookmarkSubscribeRSS Feed
Davanden
Obsidian | Level 7

I am trying to use a macro to parse some strings.  This simplified code is supposed to find the rightmost underscore.  However, the Index is resolved as zero:

 

%macro resolveindex;
%let thisvar = PriPrb_SUM;
%LET Index = %SYSFUNC(FIND("&ThisVar.","_",-33));
%mend;

 

Since I know that macro variables are always character, I tried this:

 

%LET Index = %SYSFUNC(PUT(FIND("&ThisVar.","_",-33),2.);

 

However, I get an error message that PUT function is unknown.

 

How do I get this to work?

 

1 REPLY 1
ballardw
Super User
%let thisvar = PriPrb_SUM;
%LET Index = %SYSFUNC(FIND(&ThisVar.,_,-33));

%put &index.;

Quotes in macro calls to data step functions are usually not needed since the macro processor treats everything as character.

The function to examine a macro variable is %put.

If you want to use the data step Put functions with %sysfunc you need to use either PUTN or PUTC explicitly.

Note: if your Thisvar might have commas then you have another issue as it would be interpreted as a delimiter in the function call and you would need to use on of the macro quoting functions to have the comma ignored in the Find function.

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
  • 1 reply
  • 299 views
  • 0 likes
  • 2 in conversation