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

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