BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelersgirl
Calcite | Level 5

I am trying to read in a data set from http://people.stat.sc.edu/hitchcock/champ36pres.txt. Some of the years have two champions but SAS reads in the year as missing. I am trying to bring down the year before in to the missing value.  Am I missing something in the retain line of the code to bring the year down?

DATA football;
FILENAME webpage 'http://people.stat.sc.edu/hitchcock/champ36pres.txt';
INFILE webpage FIRSTOBS=7 TRUNCOVER;
INPUT year YYYY. team $ 8-27 wins 30-31 losses 33-33 ties 35-35 coach $ 36-54;
RETAIN year;
RUN;

PROC PRINT DATA=football;
RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
DATA football;
FILENAME webpage url 'http://people.stat.sc.edu/hitchcock/champ36pres.txt';
INFILE webpage FIRSTOBS=7 TRUNCOVER;
retain year;
INPUT _year  7. team $ 8-27 wins 30-31 losses 33-33 ties 35-35 coach $ 36-54;
if not missing(_year) then year=_year;
drop _year;
RUN;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
DATA football;
FILENAME webpage 'http://people.stat.sc.edu/hitchcock/champ36pres.txt';
INFILE webpage FIRSTOBS=7 TRUNCOVER;
retain year;
INPUT year1 YYYY. team $ 8-27 wins 30-31 losses 33-33 ties 35-35 coach $ 36-54;
if not missing(year1) then year=year1;
RUN;
--
Paige Miller
Reeza
Super User

This seems to work. 

 

@first I read the year only. If it's not missing, replace the old value otherwise carry on previous value. Use trailing @ to hold the record in place.

Note that I also had to modify your FILENAME statement to get this to work properly. 

 

DATA football;
FILENAME webpage url 'http://people.stat.sc.edu/hitchcock/champ36pres.txt';
INFILE webpage FIRSTOBS=7 TRUNCOVER;
RETAIN year;
input _year 4-7 @;

if not missing(_year) then year=_year;

INPUT team $ 8-27 wins 30-31 losses 33-33 ties 35-35 coach $ 36-54;

drop _year;
RUN;

PROC PRINT DATA=football;
RUN;

@Steelersgirl wrote:

I am trying to read in a data set from http://people.stat.sc.edu/hitchcock/champ36pres.txt. Some of the years have two champions but SAS reads in the year as missing. I am trying to bring down the year before in to the missing value.  Am I missing something in the retain line of the code to bring the year down?

DATA football;
FILENAME webpage 'http://people.stat.sc.edu/hitchcock/champ36pres.txt';
INFILE webpage FIRSTOBS=7 TRUNCOVER;
INPUT year YYYY. team $ 8-27 wins 30-31 losses 33-33 ties 35-35 coach $ 36-54;
RETAIN year;
RUN;

PROC PRINT DATA=football;
RUN;

 

novinosrin
Tourmaline | Level 20
DATA football;
FILENAME webpage url 'http://people.stat.sc.edu/hitchcock/champ36pres.txt';
INFILE webpage FIRSTOBS=7 TRUNCOVER;
retain year;
INPUT _year  7. team $ 8-27 wins 30-31 losses 33-33 ties 35-35 coach $ 36-54;
if not missing(_year) then year=_year;
drop _year;
RUN;
novinosrin
Tourmaline | Level 20

@Steelersgirl  It's safe to have/read 7 columns/bytes of characters with a numeric informat 7. for the reason you made it easy for us knowing that Team values starts at column 8. 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 4 replies
  • 979 views
  • 2 likes
  • 4 in conversation