SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Free-Format Data
Mixing Input Styles


Evaluating your raw data and choosing the most appropriate input style is a very important task. You have probably worked with three primary input styles for reading raw data.


Input Style Reads
Column standard data values in fixed fields
Formatted nonstandard data values in fixed fields
List data values that are not arranged in fixed fields, but are separated by blanks or other delimiters


With some file layouts, you may need to mix input styles in the same INPUT statement in order to read the data correctly.

Look at the raw data file below and think about how to combine input styles to read these values.


1---+----10---+----20---+----30---+----40-
209-20-3721 07JAN78 41,983 SALES 2896 
223-96-8933 03MAY86 27,356 EDUCATION 2344 
232-18-3485 17AUG81 33,167 MARKETING 2674 
251-25-9392 08SEP84 34,033 RESEARCH 2956 


  • Column input is an appropriate choice for the first field because the values can be read as standard character values and are located in fixed columns.

  • The next two fields are also located in fixed columns, but the values require an informat. So, formatted input is a good choice here.

  • Values in the fourth field begin in column 28 but do not end in the same column. List input is appropriate here, but notice that some values are longer than eight characters. You need to use the : format modifier with an informat to read these values.

  • The last field does not have a common beginning or ending column, so list input is the best input style for these values.

Field Description

Starting Column

Field Width

Data Type

Input Style

Social Security #

1

11

character

column

Date of Hire

13

7

date

formatted

Annual Salary

21

6

numeric

formatted

Department

28

5 to 9

character list

Phone Extension

??

4

numeric

list


The INPUT statement to read the data should look like this:

     data perm.mixed;
        infile rawdata;
        input SSN $ 1-11 @13 HireDate date7. 
@21 Salary comma6.
Department : $9. Phone; run; proc print data=perm.mixed; run;
When you submit the PRINT procedure, the output displays values for each variable.


Obs

SSN

HireDate Salary Department Phone
1 209-20-3721 6581 41983

SALES

2896

2 223-96-8933 9619 27356

EDUCATION

2344

3 232-18-3485 7899 33167 MARKETING

2674

4 251-25-9392 9017 34033

RESEARCH

2956



back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement