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...

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 772 views
  • 0 likes
  • 3 in conversation