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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1450 views
  • 2 likes
  • 3 in conversation