DATA Step, Macro, Functions and more

input statement

Reply
Contributor
Posts: 20

input statement

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

Super User
Posts: 22,875

Re: input statement

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


 

Contributor
Posts: 20

Re: input statement

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

 

See attached.

Super User
Posts: 6,544

Re: input statement

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

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 114 views
  • 0 likes
  • 3 in conversation