Reputation: 853
I am using runSASJob to execute SAS programs in a UNIX environment.
I was wondering if there was a way to execute a portion of a SAS program from the command line.
For example, say I have a SAS program with 100 lines and there is a data step in that program that takes up lines 5-10.
Can I run lines 5-10 only from the command line?
Thanks
Upvotes: 0
Views: 178
Reputation: 3116
The following macro should address this problem and some similar ones:
%macro runMacroFromEnv
/des='Set the environment value RUNMACRO to run a macro';
%if %sysfunc( envlen( RUNMACRO ) ) > 0 %then %sysget( RUNMACRO );
%mend;
For example: if you have the following file:
%macro foo;
%put I just ran foo;
%mend;
%macro runMacroFromEnv
/des='Set the environment value RUNMACRO to run a macro';
%if %sysfunc( envlen( RUNMACRO ) ) > 0 %then %sysget( RUNMACRO );
%mend;
%runMacroFromEnv;
and invoke SAS with:
sas runMacro.sas -set RUNMACRO %foo
Then somewhere in your log, you will see:
I just ran foo
A couple of important details:
-set
works (at least) in Unix and Windows%
in -set RUNMACRO %foo
Upvotes: 0
Reputation: 9569
There are various options available to you:
option spool
is set, and you know which line numbers the 5 desired lines occupied in the log, you can replay those lines via a %include
statement.For option 3, a sample data step might look like this:
%let SHORTFILE = %sysfunc(pathname(work))/shortfile.sas;
data _null_;
infile "/path/to/100/line/file.sas" obs = 10 firstobs=5 lrecl = 32767;
file "&SHORTFILE" lrecl= 32767;
input;
put _infile_;
run;
%include "&SHORTFILE";
If you're feeling brave and you really don't want to create an extra temp file, you can use call execute to do this instead:
data _null_;
infile "/path/to/100/line/file.sas" obs = 10 firstobs=5 lrecl = 32767;
input;
call execute(_infile_);
run;
Upvotes: 1