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;
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;
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;
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;
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;
@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. 🙂
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.