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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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