Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
October 2015
(for SAS)

SAS provides several ways for a user to input data using a CARDS or DATALINES statement. In the examples the CARDS statement is used but the two statements for the most part can be used interchangeably. (The CARDS statement originates from the time when punch cards were used to store data.) Note that for each example the following statement was used to define the CITY and DISTANCE variables:

  length city $15 distance 8;

List Input, known for its simplicity

  input city $ distance; 
  cards; 
  Amsterdam 370 
  Montreal 5200 
  Auckland 22720 
  ;

Delimited Input, using the DLM= option (example uses '~' but it is possible to use other characters as the delimiter)

  infile cards dlm='~'; 
  input city $ distance; 
  cards; 
  Paris~330 
  New York~5530 
  Sydney~215660 
  ;

"Double Space" as a delimiter

  input city $ & distance; 
  cards; 
  Frankfurt 640 
  Rio de Janeiro 11060 
  Singapore 10810 
  ;

Named Input

  input city= $ distance=; 
  cards; 
  city=Copenhagen distance=953 
  distance=6800 city=Nairobi 
  city=Tokyo distance=15260 
  ;

Column Input

  input city $ 1-11 distance 13-20; 
  cards; 
  Rome 1430 
  Mexico City 10640 
  Hong Kong 13200 
  ;

Formatted Input

  input city $11. @13 distance 5.; 
  cards; 
  Stockholm 1450 
  Los Angeles 8780 
  Bangkok 12860 
  ;

It is possible to mix the methods inside an INPUT statement but use caution as unexpected results can easily occur.

Hope this was useful.

________________________________
Updated October 2, 2015