Search notes:

SAS statements: input

The input statement tells SAS how the (raw) input data looks like and how the data is to be associated with variables.
Hence, this statement creates the bridge between external data and a representation that is useful within SAS processing.
INPUT <user-specifications> <@ | @@>;
Note: there is also a function with the name input.

Styles

There are four styles for the input statement:

Missover

data tq84_ts; 

 /* 

    missover: skip over the missing german translation of six:

    otherwise ge would be assigned 3

 */
 infile datalines missover;

 input
   num
   en  $ 
   ge  $
 ;
datalines;
2 two zwei
6 six
3 three drei
1 one eins
;

proc print data=tq84_ts;
run;
Github repository about-SAS, path: /programming/statements/input/missover.sas

_infile_

data tq84_ts; 

 infile datalines;

 /* Dont assign any value to any variable: */
 input;
 
 /* _infile_ apparently stores the last read line */
 put _n_ : _infile_;
 
datalines;
Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo
dolores et ea rebum.
;

proc print data=tq84_ts;
run;
Github repository about-SAS, path: /programming/statements/input/_infile_.sas

Columns

data tq84_ts; 
  input
    num_name  $  1-10
    num_value   11-12
    num_roman $ 13-16
  ;
datalines;
one        1I
three      3III
nine       9IX
fourty-two42XLII
;
Github repository about-SAS, path: /programming/statements/input/columns.sas

At

/*

  @n are column pointers which say: move to column n.

*/

data tq84_ts; 

  input
    @1  num_name  $ 9.
    @13 num_value   2.0
    @18 num_roman $
  ;

datalines;
one      abc 1mnoI
three    def 3pqrIII
nine     ghi 9stuIX
forty-twojkl42vwxXLII
;

proc print data=tq84_ts;
run;
Github repository about-SAS, path: /programming/statements/input/at.sas

base_n-base_m-notation.sas

data tq84_ts; 

  input
    @1  (spelled1-spelled3 val1-val3)
        (3*$10. 3*2.0);

datalines;
thirteen  twenty-oneone       1321 1
seven     four      eight      7 4 8
forty-two sixty     ten       426010
twelve    nine      twenty    12 920
;

proc print data=tq84_ts;
run;
Github repository about-SAS, path: /programming/statements/input/base_n-base_m-notation.sas

relative-column-pointer.sas

data tq84_ts; 

  input
    @1  (spelled1-spelled3) ($10. +  2)  /* Start at column  1, read 10 (char) columns, then skip 2 */
    @11 (val1    -val3    ) (2.0  + 10); /* Start at column 11, read 2 (num) columns, then skip 10 */

datalines;
thirteen  13twenty-one21one        1
seven      7four       4eight      8
forty-two 42sixty     60ten       10
twelve    12nine       9twenty    20
;

proc print data=tq84_ts;
run;
Github repository about-SAS, path: /programming/statements/input/relative-column-pointer.sas

length-of-variables.sas

data tq84_s;

  infile datalines;

  length col_1 $25;
  length col_2 $10;
  length col_3 $10;

  input
    col_1
    col_2
    col_3
  ;

datalines;
x y z
one two three
foo bar baz
longerThanEightCharacters strawberry blackberry
;



proc print data=tq84_s;
run;
Github repository about-SAS, path: /programming/statements/input/length-of-variables.sas

array.sas

data tq84_data;

  array num{*} $20 num_1-num_10;
  input num_1-num_10;

datalines;
one two three four five six seven eight nine ten
eins zwei drei vier fünf sechs sieben acht neun zehn
un deux trois quattre cinque six sept huit neuf dix
run;

proc print
     data=tq84_data;
run;
Github repository about-SAS, path: /programming/statements/input/array.sas

in.sas

data _null_;

  foo   = 10;
  bar   =  2;
  baz   =  7;

  array ary{*} foo bar baz;
  
  do i = 1 to 10;
     if i in ary then put  i ' is in ary';
  end;

run;
Github repository about-SAS, path: /programming/statements/array/in.sas

See also

SAS statements, especially infile
With the datalines statement, it possible to read data that is stored with the program source rather than reading external data.
put

Index