Chapter Contents |
Previous |
Next |
CMS |
Alias: | SYSTEM |
CMS specifics: | all |
Syntax | |
Details | |
Example | |
See Also |
Syntax |
CMS ('command') |
Details |
The CMS function invokes one CMS or CP command and returns the return code that was set by execution of the command. Because the CMS or SYSTEM function is part of an executable SAS statement, you can conditionally execute certain CMS and CP commands within a SAS session (unlike the CMS statement) and to use the CMS SUBCOM facility for support.
For example, you can use the CMS function in the following assignment statement:
rc=CMS('command');
rc is a variable that contains the return code that was set by execution of the command.
Commands invoked with the CMS function are executed when the DATA step executes, not when the statement containing the function is scanned.
The limitations on CMS and CP commands in CMS subset mode also apply to the CMS function; that is, commands that use the user area are not allowed.
Example |
The following SAS program determines whether today's data file exists on an accessed minidisk. It does this using the SAS functions WEEKDAY and TODAY and by issuing a CMS STATE command. The program references five CMS files; each file contains data for one weekday.
DAY1 DATA A DAY2 DATA A DAY3 DATA A DAY4 DATA A DAY5 DATA A
The first DATA step uses information from functions TODAY and WEEKDAY in the CMS STATE command, which determines whether a data file such as DAY2 DATA * exists. If the file exists (rc=0), the program creates a macro variable called &DAILY. &DAILY contains the name of the file that exists and is used in the INFILE statement in the second DATA step. If the file does not exist, the SAS program aborts and the second DATA step is never executed.
data day; wd=weekday(today())-2; if wd=0 then wd=5; number=put(wd,1.); rc=cms('state day'||number||' data *'); if rc=0 then do; name=' "day'||number||' data" '; call symput('daily',name); end; else do; put ' The data file does not exist.'; abort return; end; run; data daily; infile &daily; input branch $ 1-20 dept 22-24 @26 revenue 10.; run;
The sample program illustrates the difference between a command invoked with the CMS function and a command invoked with the CMS statement or in CMS subset mode. Commands that are invoked with the CMS function are not invoked until execution time, after all statements in a step have been scanned. Commands that are invoked with a CMS statement or in CMS subset mode are executed when SAS encounters them while scanning the step.
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.