BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Planck
Obsidian | Level 7

Hi,

 

I would like to use a function which returns a string as a part of another string, without declaring it before.

That's very easy but I don't know

 

It's during an import from Excel:

sheet = "sheet_substrn(&datee.,max(1,length(&datee.)-3),4)"

 

It doesn't understand it need to replace the function with the value.

 

Thanks for answer, and sorry for the basic question.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You will need to switch from SAS language functions to macro language.  For some functions, such as LENGTH, there is already a macro version of the function available (%LENGTH).  But for others (SUBSTR, MAX), where there is no macro version of the function, you will need to apply %SYSFUNC to allow macro language to use the DATA step function. 

 

sheet = "sheet_%sysfunc(substr(&datee.,%sysfunc(max(1,%length(&datee.)-3)),4))"

 

I think I got the parentheses in the right places.  Also note, macro language treats text as character, so you can use SUBSTR instead of SUBSTRN.

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

I'm not sure it's very simple. 

Can you give examples of cell values and the desired outcome in SAS?

Also, please describe why you are doing this.

Data never sleeps
Astounding
PROC Star

You will need to switch from SAS language functions to macro language.  For some functions, such as LENGTH, there is already a macro version of the function available (%LENGTH).  But for others (SUBSTR, MAX), where there is no macro version of the function, you will need to apply %SYSFUNC to allow macro language to use the DATA step function. 

 

sheet = "sheet_%sysfunc(substr(&datee.,%sysfunc(max(1,%length(&datee.)-3)),4))"

 

I think I got the parentheses in the right places.  Also note, macro language treats text as character, so you can use SUBSTR instead of SUBSTRN.

Planck
Obsidian | Level 7

Thanks it works like this 🙂

Astounding
PROC Star

Glad it works, but I may have overcomplicated this a bit.  Macro language does contain a %SUBSTR function.

 

Planck
Obsidian | Level 7

Yes that's a stange solution.

But it's ok if it works, I don't ask for more 🙂 Thanks for your help!

 

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
  • 996 views
  • 2 likes
  • 3 in conversation