Automatically analyzing and documenting SAS-code

In SAS Enterprise Guide and SAS-DI you have the possibility to analyze the code for a SAS-program.

The picture below shows the Analyze Program option in SAS Enterprise Guide.

Analyzing the code should result in a conversion of the SAS-code to a SAS Enterprise Guide flow or SAS-DI flow. But none of these code analyzers are very good. Depending on the complexity of the SAS-code you put into the analyzer, they will leave you with a more or less successful conversion. And more times than not they will fail at doing the job.

But SAS comes with a procedure PROC SCAPROC that does a really good job at analyzing and documenting SAS-code.

Below is an example. The ‘attr‘ option writes additional information about the variables in the input data sets and views. The ‘expandmacros‘ option expands macro invocations into separate tasks.

proc scaproc;
record '<PATH>' attr expandmacros;
proc scaproc;

Be aware, that PROC SCAPROC isĀ not able to get information from the execution of your SAS-program flow, if you are rsubmitting to other servers.

The links below gives you further descriptions of PROC SCAPROC and its options. There’s also a guide on how to do a graphical presentation of the result fra PROC SCAPROC.

Overview of the SCAPROC Procedure

Program for parsing the output from PROC SCAPROC to create a data set with inputs and outputs.

Innovative Performance Improvements Through Automated Flowcharts In SAS

Uniqueness in data

The SAS-macro below will tell you if a variable in a dataset is unique.

Author        : 
Creation date : ddmmmyyy
Description   : Gets info about uniqness in a SAS-dataset.
Example       : %uniq(sashelp.class, name, print)
&datset   : The dataset to test.
&variable : The variable to test for uniqueness.
&print    : If the output/result should be shown in a PROC PRINT.
freq_result          : Dataset sorted with doublets as first rows.
freq_result_doublets : Data containing only the doublets.
%macro uniq(dataset, variable, print);
	proc freq data=&dataset.;
		tables &variable / noprint out=freq_result;

	proc sort data=freq_result;
		by descending count;

	data freq_result_doublets;
		set freq_result;
		where count gt 1;

	proc sql noprint;
		select count(*) into :doublets
		from freq_result_doublets
		where count gt 1

	%put --------------------------------------------------------------------------------------------;
	%put NUMBER OF DOUBLETS IN [%upcase(&dataset.)] FOR VARIABLE [%upcase(&variable.)]: &doublets.;
	%put --------------------------------------------------------------------------------------------;

	%if &doublets. eq 0 %then
		%put !!!! NO DOUBLETS !!!;
	%put --------------------------------------------------------------------------------------------;

        %if &print. ne %then
             proc print data=freq_result;