Write a Comma-Delimited File Using Formats

With some file layouts, you might need to mix input styles in the same INPUT statement in order to read the data correctly.
Table 18.1 Input Styles and the Types of Information They Read
Input Style
What It Reads
Column
standard data values in fixed fields
Formatted
standard and nonstandard data values in fixed fields
List
data values that are not arranged in fixed fields, but are separated by blanks or other delimiters
Look at the raw data file below and think about how to combine input styles to read these values.
Figure 18.41 Raw Data Showing Mixed Input Styles
Raw data that shows mixed input styles.
  • 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 must use the : format modifier with an informat to read these values.
  • The last field does not always begin or end in the same column, so list input is the best input style for those values.
Table 18.2 Input Styles to Read the Raw Data
Field Description
Starting Column
Field Width
Data Type
Input Style
Social Security Number
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
character
list
The INPUT statement to read the data should look like this:
data sasuser.mixedstyles; 
   infile rawdata; 
   input SSN $ 1-11 @13 HireDate date7. 
         @21 Salary comma6. Department : $9. Phone $; 
run; 
proc print data=sasuser.mixedstyles; 
run;
When you submit the PRINT procedure, the output displays values for each variable.
Figure 18.42 Output Created by PROC PRINT
Output that shows a table created by PROC PRINT.
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.22.160