Sample 24753: Conditionally execute code containing a single quote
Illustrate how to use double quotes in CALL EXECUTE to
prevent syntax errors originating from an unbalanced single quote.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Create test data for the PROC REPORT that will be run in the */
/* CALL EXECUTE that follows. */
data test;
input Day :$9. customers;
datalines;
Monday 82
Tuesday 100
Wednesday 76
Thursday 91
Friday 110
;
/* CALL EXECUTE can be used to generate code that does not execute until */
/* the next step boundary. Thus, it can be used to conditionally build */
/* programming logic. Care is needed when you pass a quoted string */
/* containing apostrophes to CALL EXECUTE. */
/* */
/* In the sample that follows, the argument passed to CALL EXECUTE is */
/* surrounded by single quotes. Without additional logic, the apostrophe */
/* in the label being created on the DEFINE statement will be interpreted */
/* as a closing single quote. */
/* */
/* To generate the PROC REPORT as desired */
/* */
/* proc report data=test nowd; */
/* define customers / display "Joe's Cafe"; */
/* run; */
/* */
/* build the CALL EXECUTE parameter in multiple quoted strings. */
data _null_;
if _n_=1 then do;
call execute( 'proc report data=test nowd; define customers / display '
|| ' " ' || "Joe'"|| 's Cafe" ' || '; run; ' );
end;
stop;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Joe's
Day Cafe
Monday 82
Tuesday 100
Wednesday 76
Thursday 91
Friday 110
Illustrate how to use double quotes in CALL EXECUTE to prevent syntax errors originating from an unbalanced single quote.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> CALL routines
|
| Date Modified: | 2006-09-06 03:02:54 |
| Date Created: | 2004-09-30 14:09:10 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |