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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.