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

Hi,

 

I have wrote a code to illustrate the use of %sysfunc in a open code. The first code is not using %sysfunc, instead I use macro functions :

 

  %let test=a/b/c.sas;
  %let nsys=%substr ( &test,1,%length (%scan ( &test,-1,/) ) );
  %put &nsys;

Now I would like to use the same logic but this time I will use %sysfunc with sas function ( not macro function)

  %let test=a/b/c.sas;
  %let ysys=%sysfunc ( substr ( &test,1,length (scan ( &test,-1,/) ) ) );
  %put &ysys;

But I get an error :

ERROR: Argument 3 to function SUBSTR referenced by the %SYSFUNC or %QSYSFUNC macro function is
not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.
Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is
terminated.

It looks like the type of value returned by length() is not numeric. What is the difference between the codes that make my %sysfunc version not working properly ?

 

Another question/advice, is it possible to use %sysfunc with a macro function ? example %sysfunc(%scan(&alpha,1)) or should we only use %sysfunc with non macro sas function like %sysfunc(scan(&alpha,1)) 

 

Thanks in advance

 

saskap

1 ACCEPTED SOLUTION

Accepted Solutions
saskapa
Quartz | Level 8

Hi RW9,

 

Yes I try find the path part of the name. I can deduce from your answer that I would then need for each function a %sysfunc...

 

%let test=a/b/c.sas;
%let ysys=%sysfunc(substr(&test.,1,%sysfunc(length(%sysfunc(scan(&test.,-1,/))))));
%put &ysys;

It is then providing me with a correct result.

 

Agreed, that there are easier and more elegant solution, but wanted to understand the use of %sysfunc.

 

Thanks,

saskap

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, first off you need to put another %sysfunc in to call the next function:

%let test=a/b/c.sas;
%let ysys=%sysfunc(substr(&test.,1,%sysfunc(length(scan(&test.,-1,/)))));
%put &ysys;

However that won't work as you think it will, logic isn't right.  What is it your actually trying to do.  A hint for you, if you find you are using lots of &'s, or %sysfunc or macro, then its likely a simple rethink of your problem will result in simpler easier code.  I assume you are trying to find the path part of the name?  If so there might be automatic variables available for this, or you can include better code in your actual program to identify this.

saskapa
Quartz | Level 8

Hi RW9,

 

Yes I try find the path part of the name. I can deduce from your answer that I would then need for each function a %sysfunc...

 

%let test=a/b/c.sas;
%let ysys=%sysfunc(substr(&test.,1,%sysfunc(length(%sysfunc(scan(&test.,-1,/))))));
%put &ysys;

It is then providing me with a correct result.

 

Agreed, that there are easier and more elegant solution, but wanted to understand the use of %sysfunc.

 

Thanks,

saskap

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Whilst I appreciate you marking your own post as the answer to the question, it is not very helpful to other users who are looking for the answer to the question.

 

In terms of %sysfunc(), that runs one SAS function, hence if you have multiple functions then you need several %sysfunc's.  The simple answer to:

"but wanted to understand the use of %sysfunc." 

Is that there is rarely, if ever a need to use it.  Proper well thought out code does not need the use of any macro code.

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
  • 3 replies
  • 1734 views
  • 0 likes
  • 2 in conversation