Q: How to column input in SAS My data set is below and I need to type it out in column format.
I don't understand how to read it and figure out which column ranges to put in next to the variables. I see people put 1-2, 4-7, etc. next to the variables but where is that coming from??
input id team $ startweight endweight;

1023 red    189 165
1049 yellow 145 124
1219 red    210 192
1246 yellow 194 177
1078 red    127 118
1221 yellow 220   .
1095 blue   135 127
1157 green  155 141
1331 blue   187 172
1067 green  135 122
1251 blue   181 166
1333 green  141 129
1192 yellow 152 139
1352 green  156 137
1262 blue   196 180
1087 red    148 135
1124 green  156 142
1197 red    138 125
1133 blue   180 167
1036 green  135 123
1057 yellow 146 132
1328 red    155 142
1243 blue   134 122
1177 red    141 130
1259 green  189 172
1017 blue   138 127
1099 yellow 148 132
1329 yellow 188 174
;
run;


A: SAS has a number of ways to read in data.
With list input, you just ... list ... out the columns!
input id team $ startweight endweight;

However, that relies on the columns being in a delimited format - meaning, there is some character (space, comma, etc.) separating the fields.
If that's not the case, and instead it's just positional, character by character - meaning, the first two characters are always the ID, the next 4 characters are the team, etc. - then you can use column input or formatted input.
Column input:
input id 1-2 team $ 4-7 startweight 8-15 endweight 16-23;

Formatted input:
input @1 id 2. @4 team $4. @8 startweight 8. @16 endweight 8. ;

Column input just puts the start-end column after the variable name, optionally with $ for character variables.   Formatted input goes further; it uses pointer control to say where to start, and then it gives an informat to define how to input the data.  The informat is useful when you're, say, inputting date values.
See the documentation for the input statement for more information on various input types (including several fun ones not mentioned here!)

This would input your example data:
data want;
  input 
    id 1-4 
    team $ 6-11 
    startweight 13-15 
    endweight 17-19
  ;
datalines;
1023 red    189 165
1049 yellow 145 124
1219 red    210 192
1246 yellow 194 177
1078 red    127 118
1221 yellow 220   .
1095 blue   135 127
1157 green  155 141
1331 blue   187 172
1067 green  135 122
1251 blue   181 166
1333 green  141 129
1192 yellow 152 139
1352 green  156 137
1262 blue   196 180
1087 red    148 135
1124 green  156 142
1197 red    138 125
1133 blue   180 167
1036 green  135 123
1057 yellow 146 132
1328 red    155 142
1243 blue   134 122
1177 red    141 130
1259 green  189 172
1017 blue   138 127
1099 yellow 148 132
1329 yellow 188 174
;
run;

As would this:
data want;
  input 
      @1 id 4. 
      @6 team $6.
      @13 startweight 3.
      @17 endweight 3.
  ;
datalines;
1023 red    189 165
1049 yellow 145 124
1219 red    210 192
1246 yellow 194 177
1078 red    127 118
1221 yellow 220   .
1095 blue   135 127
1157 green  155 141
1331 blue   187 172
1067 green  135 122
1251 blue   181 166
1333 green  141 129
1192 yellow 152 139
1352 green  156 137
1262 blue   196 180
1087 red    148 135
1124 green  156 142
1197 red    138 125
1133 blue   180 167
1036 green  135 123
1057 yellow 146 132
1328 red    155 142
1243 blue   134 122
1177 red    141 130
1259 green  189 172
1017 blue   138 127
1099 yellow 148 132
1329 yellow 188 174
;
run;

