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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 594 views
  • 2 likes
  • 4 in conversation