Tejas Nikam
Tejas Nikam

Reputation: 19

Reading the text file incorrectly in sas

Problem Statement: I have a text file and I want to read it using SAS INFILE function. But SAS is not giving me the proper output.

Text File:
Akash    18 19 20
Tejas       20 16
Shashank 16 20
Meera    18    20

The Code that I have tried:

DATA Arr;
INFILE "/folders/myfolders/personal/SAS_Array .txt" missover;
INPUT Name$ SAS DS R;
RUN;

PROC PRINT DATA=arr;
RUN;

While the result i got is :

Table of Contents
Obs Name    SAS DS  R
1   Akash   18  19  20
2   Tejas   20  16  .
3   Shashank16  20  .
4   Meera   18  20  .

Which is improper. So what is wrong with the code? I need to read the file in SAS with the same sequence of marks as in text file. Please help.

Expected result:

Table of Contents
Obs Name    SAS DS  R
1   Akash   18  19  20
2   Tejas    .  20  16  
3   Shashank16  20  .
4   Meera   18   .  20  

Thanks in advance.

Upvotes: 1

Views: 573

Answers (1)

user2877959
user2877959

Reputation: 1792

If that text file is tab-delimited, you should specify the delimiter in the infile statement and use the dsd option to account for missing values:

DATA Arr;
INFILE "/folders/myfolders/personal/SAS_Array .txt" missover dlm='09'x dsd;
INPUT Name $ SAS DS R;
RUN;

PROC PRINT DATA=arr;
RUN;

EDIT: after editing, your sample text file now looks fixed-width rather than space-delimited. In that case you should be using column input:

DATA Arr;
INFILE "/folders/myfolders/personal/SAS_Array .txt" missover;
INPUT Name $1-9 SAS 10-12 DS 13-15 R 16-18;
RUN;

example with datalines:

DATA Arr;
INFILE datalines missover;
INPUT Name $1-9 SAS 10-12 DS 13-15 R 16-18;
datalines;
Akash    18 19 20
Tejas       20 16
Shashank 16 20
Meera    18    20
RUN;

Upvotes: 1

Related Questions