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; 
  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; 
  New York~5530 

"Double Space" as a delimiter

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

Named Input

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

Column Input

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

Formatted Input

  input city $11. @13 distance 5.; 
  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