EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer
Physics
C.S.


SAS programming Skills
SAS Automation by _null_ and %include statement

Question: We want to run a series of repeated macors, the parameters in the macros are dynamically from the previous SAS procedures.
How can we automate this process? so that after one click to run SAS, we can generate the parameters from the SAS procedures, then automatically run the macros based on those parameters.

Answer: By using _null_ and %include statements,
we can automate a lot of SAS assignments.

Example: We are using the following example to demonstate, say we want to output employee seperately for different company, here is the data quickview:

        /***************************************************/
        data example;
        input id 1-2 company $4-4;
        datalines;
        01 A
        02 A
        03 B
        04 C
        ; run;

        /***************************************************/
        %macro output(companyid);
        proc print data=example(where=(company="&companyid."));
        run;
        %mend;   /* The macro to generate the output */

        %let outfile=directory\f1.sas;   /* specify output file containing macros*/

        /***************************************************/
        data _null_;
        set example;
        file "&outfile";   /* output to a sas file &outfile containing the macros*/
        put '%output(' company ");";
        run;

        data _null_;                   /* _null_ statement to run the macros */
        %include "&outfile";   /* that have been generated in "&outfile" */
        run;
        /***************************************************/


Summary: _null_ statement is very useful in SAS programming, it can be used in different situations to achieve various goals. Here is a list of pdf files for different usage of _null_ statement.

Report Creation Using Data _NULL_ Statement (pdf slides)

In this paper, reports and tables can be created using PROC REPORT, PROC PRINT and other procedures. However, there are times when the standard procedure output cannot meet the report requirements. In those cases, reports creation using the DATA _NULL_ step is the solution. The objective of this paper is to discuss the techniques used to create a data _NULL_ report.

Automation of Clinical Trial Laboratory Data (pdf slides)

This paper discusses an approach in building and using specialized SAS program modules in order to automate the process of reading clinical laboratory data from an Excel workbook into SAS using SAS/BASE and DDE. This approach minimizes the manual intervention.

The Power of TABLE Templates and DATA _NULL_ Statement (pdf slides)

Are you a DATA step programmer? Do you want to route DATA _NULL_ output to the Output Delivery System (ODS)? Do you want to convert classic DATA _NULL_ and FILE PRINT programs to take advantage of the ODS? This paper explains how to create and use a custom TABLE template with a DATA _NULL_ program. Through the use of concrete examples, you will learn how to become a power user of custom TABLE templates and DATA _NULL_. Topics covered include defining a new template, defining headers and footers, using GENERIC columns, and performing traffic-lighting based on data cell values.

Related links:

Continue to: How to read dynamic macro parameters?   SAS tutorial home
Back to: How to send email in SAS part-II: email account settings   Statistics tutorial home