SAS Named Input - Reading External text Files

Under very specific circumstances when input data is in the following format then one has no other option than using named input style.

For example data must be like given below;

External File: empDetail.txt

id=1232 name=Rogger Jones age=32 gender=M

id=1233 name=Nicole Davis age=23 gender=F

id=1013 name=Rachel Brown age=27 gender=F

id=1014 name=Michael Daniel age=29 gender=M

Here each variables in the source file is having its own name followed by '=' sign and then by actual value.

code snippet to read this kind of file is given below,

SAS Code

data temp;

infile "D:\empDetail.txt";

INPUT id= name=$20. age= gender=$;

run;

proc print data=temp;

run;

Following is the output generated with the code above. Please note that for employee name we have mentioned the informat as $20. to read the complete name extending default 8 characters length.

Output: