Help using Base SAS procedures

Call Execute syntax

Not applicable
Posts: 0

Call Execute syntax

I am trying to understand how Call Execute works.. I tried a very simple program which creates a library reference

Below is sample code..

data _null_;
set files;
call execute('LIBNAME sasdata2 ''C:\DAG\SAS\Samples\'';'


It runs fine with following in the log -

+ LIBNAME sasdata2 'C:\DAG\SAS\Samples\';
NOTE: Libref SASDATA2 was successfully assigned as follows:

Now if I change my code to use a variable instead of actual string value for libname
as below

data _null_;
set files;
call execute('LIBNAME sasdata2 '''||folderName||''';'


I get the following -

NOTE: CALL EXECUTE generated line.
1 + LIBNAME sasdata2 'C:\DAG\SAS\Samples\
2 +
WARNING: The quoted string currently being processed has become more than 262 characters long. You may have
unbalanced quotation marks.
3 + ';
ERROR: Invalid physical name for library SASDATA2.
ERROR: Error in the LIBNAME statement.
4 + LIBNAME sasdata2 'C:\DAG\SAS\Samples\
5 +

it seems to be taking the right value from the dataset files. I tried some changes in quoatations i have, to see if there is any issue. But didn't help.

Any suggestions??

Super Contributor
Super Contributor
Posts: 3,176

Re: Call Execute syntax

Posted in reply to deleted_user
The SAS variable is padded with blanks - you need to use TRIM against your variable. You may want consider building the command in a SAS variable and then use the SAS variable in your CALL EXECUTE rather than attempting to build the command string in the CALL - it may be easier to debug that way as well.

Scott Barry
SBBWorks, Inc.
Respected Advisor
Posts: 3,852

Re: Call Execute syntax

Posted in reply to deleted_user
To create LIBREFS from meta data it might be easier to use the LIBNAME function. You can also easily test the return code.
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation