I have 5 variables: year_a, year_b, year_c, year_d, year_e
For most of the observations, all but 1 are missing, but some have multiple years reported. I want to create a new variable year, that has the smallest year reported for years a-e. If anyone can walk me through the steps on how to do this (I assume this is an array, but I am not good with arrays yet) I would appreciate it.
year_a year_b year_c year_d year_e
. . 1990 . .
1979 1985 . . .
year
1990
1979
data want;
set have;
min_year=min(year_a,year_b,year_c,year_d,year_e);
run;
Data have;
Input year_a year_b year_c year_d year_e;
cards;
. . 1990 . .
1979 1985 . . .
run;
data want;
set have;
array yr year_:;
year=min(of yr(*));
keep year;
run;
@r_behata why not
data want;
set have;
year=min(of year_:);
keep year;
run;
I don't see the ARRAY adding any benefit here.
Also, I don't usually advise users to use the year_: syntax because I never know what other variables are in HAVE that begin with year_. Naturally, when you are programming your own code and you know the data sets, you will know that year_: refers only to the variables of interest (or not).
Feeling bored, so tolerate me
Data have;
Input year_a year_b year_c year_d year_e;
cards;
. . 1990 . .
1979 1985 . . .
run;
data want;
set have;
min_year=smallest(1,of year_:);
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.