Add-Innovation Home

About Add-Innovation

Contact Us

  SAS Institute logo.    Use of SAS Formats.

SAS Formats are widely used to check the validity of data against a predefined list of values (such as in the first example in this section), or to change the format of input data. Often they are inefficiently used when applying the format to the input data by creating two fields rather than one, and formatting each one individually.

For example, using the format created by the Control Dataset defined in example 1 ;

Data OddProds;
    Infile GenRev EOF=PutItOut;
    Input @1 DistAcc KeepAc. @;
    If DistAcc;
    NumAcc + 1;
    Input @290 TotCRev 15.;
    TotRev + TotCRev;
    Return;
PutItOut: Put ‘Number of Accounts = ‘ NumAcc /
            ‘Total Call Revenue = ‘ TotRev;

is more efficient than ;

Data OddProds;
    Infile GenRev EOF=PutItOut;
    Input @1 DistAcc $10. @;
    If Input(DistAcc,KeepAc.);
    NumAcc + 1;
    Input @290 TotCRev 15.;
    TotRev + TotCRev;
    Return;
PutItOut: Put ‘Number of Accounts = ‘ NumAcc /
            ‘Total Call Revenue = ‘ TotRev;

because the variable DistAcc must first be input into a ten character field, then tested against the KeepAc format. Creating a new field (such as KeepIt=Input(DistAcc,KeepAc.);) and then testing the value of this field (e.g. If Keepit=1) is even more inefficient.

The statement TotRev + TotCRev implies that the variable TotRev is automatically retained. If the value of TotCRev is missing, the value of TotRev is unchanged.

The ‘/’ symbol appearing on the Put statement throws a new line (so multiple PUT statements are not required).