/* LIST DATA */ /* A very common format for raw data is "list" data. Most typically this will have one observation per line and data values are separated by one or more spaces. This is about the simplest kind of data to read into a SAS data set. */ data club1; input idno name $ team $ strtwght endwght; cards; 1023 David red 189 165 1049 Amelia yellow 145 124 1219 Alan red 210 192 1246 Ravi yellow 194 177 1078 Ashley red 127 118 1221 Jim yellow 220 . ; proc means data=club1 maxdec=2; class team; var strtwght endwght; run; /* for comma-separated values use "dsd" */ data club2; infile cards dsd; input idno name $ team $ strtwght endwght; cards; 1023,David,red,189,165 1049,Amelia,yellow,145,124 1219,Alan,red,210,192 1246,Ravi,yellow,194,177 1078,Ashley,red,127,118 1221,Jim,yellow,220,. ; proc means data=club2 maxdec=2; class team; var strtwght endwght; run; * Note that more than one space is treated as if it were a single space. Note, too, that this means you cannot simply use a space to indicate a missing value. Missing values are represented by a period, ".".; data morethanonespace; input idno name $ team $ strtwght endwght; cards; 1023 David red 189 165 1049 Amelia yellow 145 124 1219 Alan red 210 192 1246 Ravi yellow 194 177 1078 Ashley red 127 118 1221 . yellow 220 . ; proc means data= morethanonespace maxdec=2; class team; var strtwght endwght; run; * In a comma delimited file, no placeholder for missing values is required, but spaces and periods are OK; data commas; infile cards dsd; input idno name $ team $ strtwght endwght; cards; 1023,,red, ,165 1049,Amelia,yellow,145,124 1219,Alan,red,210,192 1246,Ravi,yellow,194,177 1078,Ashley,red,127,118 1221,Jim,yellow,220,. ; run; proc means data=commas maxdec=2; class team; var strtwght endwght; run; * If SAS reaches the end of an input line without finding values for all the variables, it continues reading from the next line. There will be a NOTE in the log telling/ warning you that this has happened.; data flowtonextline; input idno name $ team $ strtwght endwght; cards; 1023 David red 189 165 1049 Amelia yellow 145 124 1219 Alan red 210 192 1246 Ravi yellow 194 177 1078 Ashley red 127 118 1221 Jim yellow 220 . ; run; proc means data=flowtonextline maxdec=2; class team; var strtwght endwght; run; * This can lead to unexpected results if there are not enough data values.; data unexpected; input idno name $ team $ strtwght endwght; cards; 1023 David red 189 1049 Amelia yellow 145 124 1219 Alan red 210 192 1246 Ravi yellow 194 177 1078 Ashley red 127 118 1221 Jim yellow 220 . ; proc means data=unexpected maxdec=2; class team; var strtwght endwght; run; proc print data=unexpected; title 'Weight Club Members'; run; * Note also that you do not have to read in all the variables, but you do have to read in everything up to the last variable you want; data shortlist; input idno name $ team $; cards; 1023 David red 189 1049 Amelia yellow 145 124 1219 Alan red 210 192 1246 Ravi yellow 194 177 1078 Ashley red 127 118 1221 Jim yellow 220 . ; proc freq data=shortlist; run;