Back to Tech Corner
SAS Programming

SAS Programming - PROC SCAPROC

What Does the SCAPROC Procedure Do?

The SCAPROC procedure uses the SAS Code Analyzer, which captures information about input, output, and the use of macro symbols from a SAS job while it is running. The procedure; Code Analyzer can write this information and the original SAS code to an external file s well. The SCAPROC procedure is helpful to generate a grid-enabled job that runs independent pieces of the job in parallel (not discussed in this article).

The SCAPROC procedure could be submitted from a CMD line as well as submitted traditionally as a batch and or in SAS code in the SAS Editor window.

Using SAS Code Analyzer helps determine the steps that could be run in parallel and or help implement "Scale Up" & "Scale Out" methodologies. More detailed discussion on that concept will be coming in the next month's article so keep an eye out for it.

The following command runs your SAS job with the SAS Code Analyzer from your operating system's command line:

sas yourjob.sas -initstmt "proc scaproc; record '/some/path/externalfile*.txt*'; run;"

Explanation

sas

is the command used at your site to start SAS.

yourjob.sas

is the name of the SAS job that you want to analyze.

externalfile.txt

is the name of the file that will contain a copy of your SAS code. The file will also contain the comments that are inserted to show input and output information, macro symbol usage, and other aspects of your job. Please ensure the path has appropriate permissions for the externalfile.txt. At the end of this article sample is included how to use the PROC in SAS code.

Special Considerations

Some tasks of grid-enabled jobs can have dependencies on previous tasks. PROC SCAPROC combines and reorders these tasks based on their dependencies to the preceding tasks. Combining the tasks and submitting them in the same work unit enables faster processing of the tasks. The NOOPTIMIZE argument of the GRID option disables the combining and reordering of tasks of grid-enabled jobs.

To use GRID statement your site has to license SAS Grid Manager or SAS/CONNECT. SAS Grid Manager enables your generated grid job to run on a grid of distributed machines. SAS/CONNECT enables your generated grid job to run on parallel SAS sessions on one symmetric multiprocessing (SMP) machine.

PROC SCAPROC Use in SAS Code

We wrote a sas code utilizing PROC SCAPROC (see below)

/* 1 Starting PROC SCAPROC option to write an external file and path is also provided */
proc scaproc;
record '/data/saspgms/procscaproc.txt';
run;

/* 2 Normal any SAS code */
data a;
do i = 1 to 100000;
j = cos(i);
output;
end;
run;

/* 3 Another SAS step added */
proc print data=a(obs=25);
run;

/* 4 Continuing with adding another step */
proc means data=a;
run;

/* 5 Ending with SCAPROC feature to write all processing and analysis and end the code */
proc scaproc;
write;
run;

Code Explanation:

  1. Starting PROC SCAPROC option to write an external file and path is also provided
  2. Normal any SAS code
  3. Another SAS step added
  4. Continuing with adding another step
  5. Ending with SCAPROC feature to write all processing and analysis and end the code.

Submit Code:

sas -sysin /data/saspgms/procscaproc.sas

Results (Details not shown, normal log and output)

External File (The original SAS code as well as SCAPROC output included)

/* JOBSPLIT: JOBSTARTTIME 14DEC2022:21:02:01.66 */

/* JOBSPLIT: TASKSTARTTIME 14DEC2022:21:02:01.67 */

/* JOBSPLIT: DATASET OUTPUT SEQ WORK.A.DATA */

/* JOBSPLIT: LIBNAME WORK V9 '/saswork/SAS_work91B5000033F6_sasva.aii3.local' */

/* JOBSPLIT: ELAPSED 25 */

/* JOBSPLIT: SYSSCP LIN X64 */

/* JOBSPLIT: PROCNAME DATASTEP */

/* JOBSPLIT: STEP SOURCE FOLLOWS */

data a;
do i = 1 to 100000;
j = cos(i);
output;
end;
run;

/* JOBSPLIT: TASKSTARTTIME 14DEC2022:21:02:01.69 */

/* JOBSPLIT: ITEMSTORE INPUT SASUSER.TEMPLAT */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLMST */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLLISTING */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLSTYLES */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLPROCTEMPLATE */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLBASE */

/* JOBSPLIT: DATASET INPUT SEQ WORK.A.DATA */

/* JOBSPLIT: LIBNAME WORK V9 '/saswork/SAS_work91B5000033F6_sasva.aii3.local' */

/* JOBSPLIT: FILE OUTPUT /data/saspgms/procscaproc.lst */

/* JOBSPLIT: ELAPSED 54 */

/* JOBSPLIT: PROCNAME PRINT */

/* JOBSPLIT: STEP SOURCE FOLLOWS */

proc print data=a(obs=25);
run;

/* JOBSPLIT: TASKSTARTTIME 14DEC2022:21:02:01.75 */

/* JOBSPLIT: DATASET INPUT SEQ WORK.A.DATA */

/* JOBSPLIT: LIBNAME WORK V9 '/saswork/SAS_work91B5000033F6_sasva.aii3.local' */

/* JOBSPLIT: ITEMSTORE INPUT SASUSER.TEMPLAT */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLPROCSUMMARY */

/* JOBSPLIT: ITEMSTORE INPUT SASHELP.TMPLCOMMON */

/* JOBSPLIT: FILE OUTPUT /data/record.txt */

/* JOBSPLIT: SYMBOL GET SYSSUMSTACKODS */

/* JOBSPLIT: SYMBOL GET SYSSUMTRACE */

/* JOBSPLIT: SYMBOL GET SYSZSQLCAS */

/* JOBSPLIT: ELAPSED 28 */

/* JOBSPLIT: PROCNAME MEANS */

/* JOBSPLIT: STEP SOURCE FOLLOWS */

proc means data=a;
run;

/* JOBSPLIT: JOBENDTIME 14DEC2022:21:02:01.77 */

/* JOBSPLIT: END */