Help using Base SAS procedures

Reading SAS file

Reply
Contributor
Posts: 50

Reading SAS file

Hi All,

I am using the code:


DATA test;
INPUT   X : 2
            Y : 1.
            A & $11.
            Z : 1.;
DATALINES;
1 2 HELLO WORLD 3
4 5 S BEHNOI 6
;
PROC PRINT DATA=Test;
RUN;

This doesnt read the file correctly. I do not want to change the order of my datalines, could you suggest what change I shoukd make in the Input lines so as to read the data correctly.

Kind Regards

Siddharth

Super User
Super User
Posts: 6,499

Re: Reading SAS file

I think your question is how can you read the variable length string in the middle of the line that might had embedded blanks and does NOT have two spaces after it to indicate the end of the variable length string.

In general you cannot.  So you will have to use some other method to determining where the number at the end of the line starts.

DATA test;

  INPUT  x y a & $14. ;

  j=input(scan(a,-1,' '),2.);

  a=substr(a,1,length(a) - length(scan(a,-1,' ')));

  put / _infile_ / (_all_) (=);

DATALINES;               

1 2 HELLO WORLD 3              

4 5 S BEHNOI 6  

;


1 2 HELLO WORLD 3

x=1 y=2 a=HELLO WORLD j=3

4 5 S BEHNOI 6

x=4 y=5 a=S BEHNOI j=6


Ask a Question
Discussion stats
  • 1 reply
  • 150 views
  • 4 likes
  • 2 in conversation