BookmarkSubscribeRSS Feed
Melk
Lapis Lazuli | Level 10

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

 

 

 

Ask your question

year

1990

1979

4 REPLIES 4
PaigeMiller
Diamond | Level 26
data want;
    set have;
    min_year=min(year_a,year_b,year_c,year_d,year_e);
run;
--
Paige Miller
r_behata
Barite | Level 11
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;
PaigeMiller
Diamond | Level 26

@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).

 

--
Paige Miller
novinosrin
Tourmaline | Level 20

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;

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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