Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2023-03-30 20:36:46
Size: 1051
Comment:
Revision 3 as of 2023-03-30 20:41:10
Size: 1267
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

SAS has [[SAS/Import|procedures for automating the import of data files]], but sometimes it's necessary to manually read data from a text file.
Line 40: Line 42:
        output LIBREF.TABLE1;
    end;
Line 45: Line 49:
    output;         output LIBREF.TABLE2;
    end;

SAS Reading Data

SAS has procedures for automating the import of data files, but sometimes it's necessary to manually read data from a text file.


Input

The primary way to read data into a SAS table is with a data step and the INFILE, INPUT, and OUTPUT statements.

InFile Statement

data LIBREF.TABLE;
    infile "data.txt" pad missover lrecl=80;
run;

The LRECL option specifies the fixed-width size of a record. The MISSOVER and PAD options together ensure that unspecified fields are set to missing.

Input Statement

data LIBREF.TABLE;
    infile "data.txt" pad missover lrecl=80;
    input
        RECTYPE  $ 1-1 @
    ;
        
    if RECTYPE = "1" then do;
        input
            RECTYPE  $ 1-1
            VAR1       2-5
        ;
        output LIBREF.TABLE1;
    end;
    else RECTYPE = "2" then do;
        input
            RECTYPE  $ 1-1
            VAR1       2-2
        ;
        output LIBREF.TABLE2;
    end;
run;

As demonstrated above, records can be partially input, processed, then completely input later.


CategoryRicottone

SAS/ReadingData (last edited 2023-03-30 20:41:10 by DominicRicottone)