DATA Step, Macro, Functions and more

CALL EXECUTE example

Accepted Solution Solved
Reply
Super Contributor
Posts: 271
Accepted Solution

CALL EXECUTE example

[ Edited ]

Here I have an example of using CALL EXECUTE. I wonder why the second code does not work when I omit the concatenation oeprator.  

data test;
input a $;
cards;
1
2
3
;

data _null_;
	set test end=last;
    call execute('proc print data=sashelp.class (obs='||a||'); run;');
run;

data test;
input a $;
cards;
1
2
3
;

data _null_;
	set test end=last;
    call execute('proc print data=sashelp.class (obs='a'); run;');
run;

 

 

 


Accepted Solutions
Solution
‎03-07-2016 09:57 AM
Super User
Super User
Posts: 7,942

Re: CALL EXECUTE example

Posted in reply to SAS_inquisitive

The call execute function requires a string to be passed to it as its only parameter. This

'proc print data=sashelp.class (obs='a'); run;'

is not a string, it is two strings:

'proc print data=sashelp.class (obs='

'); run;'

and something undefined.  

Function form:

call execute(<string>);

By using the concatenate symbols you are creating one string out of the two given strings and the value held in the variable a.

 

One other thing, as a string in the dataset is given a length of 8 (as you didn't define it!) you may want to use cats:

data _null_;
  set test end=last;
  call execute(cats('proc print data=sashelp.class (obs=',a,'); run;'));
run;

This should remove any blanks around a.

 

 

 

View solution in original post


All Replies
Super User
Posts: 7,771

Re: CALL EXECUTE example

Posted in reply to SAS_inquisitive

This message:

ERROR 253-185: The EXECUTE subroutine call has too many arguments.

provides the answer.

CALL EXECUTE expects ONE argument of type character. You are supplying three: a string constant, a variable of type character, and another string constant.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,780

Re: CALL EXECUTE example

Posted in reply to SAS_inquisitive

Because it isn't valid SAS code. The string isn't being created, there's no default concatenation. 

Solution
‎03-07-2016 09:57 AM
Super User
Super User
Posts: 7,942

Re: CALL EXECUTE example

Posted in reply to SAS_inquisitive

The call execute function requires a string to be passed to it as its only parameter. This

'proc print data=sashelp.class (obs='a'); run;'

is not a string, it is two strings:

'proc print data=sashelp.class (obs='

'); run;'

and something undefined.  

Function form:

call execute(<string>);

By using the concatenate symbols you are creating one string out of the two given strings and the value held in the variable a.

 

One other thing, as a string in the dataset is given a length of 8 (as you didn't define it!) you may want to use cats:

data _null_;
  set test end=last;
  call execute(cats('proc print data=sashelp.class (obs=',a,'); run;'));
run;

This should remove any blanks around a.

 

 

 

Super Contributor
Posts: 271

Re: CALL EXECUTE example

[ Edited ]

Thank you, all. I was assuming I was creating a string by enclosing variable a in quotation marks.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 459 views
  • 3 likes
  • 4 in conversation