Making an empty dataset in SAS

The code below shows you how to make an empty dataset in SAS.
If you omit the if-sentence  and below, then you will get an empty row in the dataset.

data StatusTable;
 length Dataset $100 Message $150 Status $10;
 call missing(Dataset, Message, Status);
 if _N_ = 0 then output;
 stop;
run;

This can also be done a bit easier in SQL.

proc sql noprint;
create table Dataset
(
Dataset char 100,
Message char 150,
Status char 10
);
quit;

3 thoughts on “Making an empty dataset in SAS”

  1. Ummm, wouldn’t this code be more straightforward?

    data StatusTable;
    length Dataset $100 Message $150 Status $10;
    stop;
    run;

    At the top of the processing loop, SAS creates the empty dataset, ready to be written to, and automatically fills the PDV with missing values. The STOP statement keeps SAS from writing anything into the dataset, leaving it empty.

  2. You can use a WHERE that is always false to limit the output to zero observations:

    data StatusTable(WHERE=(1=0));
    length Dataset $100 Message $150 Status $10;
    call missing(Dataset, Message, Status);
    run;

Leave a Reply

Your email address will not be published. Required fields are marked *