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.
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.
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.
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.
Thanks it works like this 🙂
Glad it works, but I may have overcomplicated this a bit. Macro language does contain a %SUBSTR function.
Yes that's a stange solution.
But it's ok if it works, I don't ask for more 🙂 Thanks for your help!
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.
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.