BookmarkSubscribeRSS Feed
Siddharth123
Obsidian | Level 7

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

1 REPLY 1
Tom
Super User Tom
Super User

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


hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 938 views
  • 4 likes
  • 2 in conversation