BookmarkSubscribeRSS Feed
elsalam
Calcite | Level 5

What is the difference between these two txt file?  I am unable to read the second one.

 

They seems to have the same free style format and embedded blank.

 

1) data file

 

my code:  I am able to run this one.

 

data shortnamesds;

infile ' /home/coccus030/sasuser.v94/nfldata2.txt' firstobs=2;
*/ @20 to indicate SAS to read at 20  city and year are too close to each other;
input City & $16. @20 Year Team $;

run;

 

----+----1----+----2----+----3
Baltimore 2012 Ravens
Cincinnati 2012 Bengals
Cleveland 2012 Browns
Pittsburgh 2012 Steelers
Chicago 2012 Bears

 

2) data file

 

Bellfort Yes No Yes Yes Yes Yes Yes Yes yes
North Carolina Yes No Yes Yes Yes Yes Yes Yes yes
South Raleigh Yes No Yes Yes Yes Yes Yes Yes yes

 

 

My code:  Unable to run

data answer;
infile '/home/coccus030/sasuser.v94/audit.txt';

input State & $16. @17 Q1 $ Q2 $ Q3 $ Q4 $ Q5 $ Q6 $ Q7 $ Q8 $ Q9 $;
run;

 

Thx

3 REPLIES 3
Reeza
Super User

Did you properly account for the two words in the second data set with the double space?

 

If you post your code in the HTML editor vs a code box there's no way to verify that, so you need to ensure it is in SAS or the text file. 

 

 


@elsalam wrote:

What is the difference between these two txt file?  I am unable to read the second one.

 

They seems to have the same free style format and embedded blank.

 

1) data file

 

my code:  I am able to run this one.

 

data shortnamesds;

infile ' /home/coccus030/sasuser.v94/nfldata2.txt' firstobs=2;
*/ @20 to indicate SAS to read at 20  city and year are too close to each other;
input City & $16. @20 Year Team $;

run;

 

----+----1----+----2----+----3
Baltimore 2012 Ravens
Cincinnati 2012 Bengals
Cleveland 2012 Browns
Pittsburgh 2012 Steelers
Chicago 2012 Bears

 

2) data file

 

Bellfort Yes No Yes Yes Yes Yes Yes Yes yes
North Carolina Yes No Yes Yes Yes Yes Yes Yes yes
South Raleigh Yes No Yes Yes Yes Yes Yes Yes yes

 

 

My code:  Unable to run

data answer;
infile '/home/coccus030/sasuser.v94/audit.txt';

input State & $16. @17 Q1 $ Q2 $ Q3 $ Q4 $ Q5 $ Q6 $ Q7 $ Q8 $ Q9 $;
run;

 

Thx


 

elsalam
Calcite | Level 5

I was able to read the data but not at the right position.

 

See attached.

Astounding
PROC Star

You are using & within the INPUT statement, without understanding what it means.  Take a look, this should clear it up:

 

http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n0lrz3gb7m9e4rn137op544ddg0v.htm&docs...

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1278 views
  • 0 likes
  • 3 in conversation