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!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.