Search code examples
sasdata-entry

Formatting Data for SAS


What should I expect when I actually upload a file? I'm trying to upload a text file with a bunch of columns each one giving data points for a categorical or numerical variable. SAS reads the file but then says 'invalid data for ____' for almost every line. Is there a straightforward way to format the columns of data so that SAS can read it? Sample lines of data are as follows:

WCM2B W C M 2 B Z.G 2 18.4 10.7 g

WCM2B W C M 2 B Z.G 2 17.6 10.8 g

WCM2B W C M 2 B Z.G 2 20.1 12.1 g


Solution

  • I'm still learning SAS but this should work.

    data test_table;
    input A $6. B $2. C $2. D $2. E 2. F $2. G $4. H $2. I 4. J 4. K $2.;
    datalines;
    WCM2B W C M 2 B Z.G 2 18.4 10.7 g
    WCM2B W C M 2 B Z.G 2 17.6 10.8 g
    WCM2B W C M 2 B Z.G 2 20.1 12.1 g
    ;run;
    

    The data test_table; makes the table name, the input is the column name followed by number of spaces, then datalines is your data.