How do I create a new variable that is equal to the earliest of a certain amount of date variables?

Reply
New Contributor
Posts: 3

How do I create a new variable that is equal to the earliest of a certain amount of date variables?

Good afternoon eveyrone!

I am stuck on what is now a complicated project.  I'm trying to create this new variable for an analysis I am trying to run.  Please help!

Thanks!

Super User
Posts: 19,855

Re: How do I create a new variable that is equal to the earliest of a certain amount of date variables?

Posted in reply to ScottyB_73

You have to provide more information.

What does your data look like. Is the certain amount fixed or variable? Are you doing this once or many times...

Sample data and output is good.

Super User
Posts: 5,516

Re: How do I create a new variable that is equal to the earliest of a certain amount of date variables?

Posted in reply to ScottyB_73

If you need this earliest date for each observation, it's relatively easy:

earliest_date = min(birth_date, graduation_date, retirement_date, start_date, end_date, event_date);

If you need something else, you'll have to explain more.

Super Contributor
Posts: 418

Re: How do I create a new variable that is equal to the earliest of a certain amount of date variables?

Posted in reply to ScottyB_73

Similarly to what Astounding said, going a different path, if you need to look at a column and then determine what the minimum date was within that column, proc sql is an easy solution.

proc sql;

create table earliest_date as

select min(DateField)

from YOUR_OLD_DATA:

quit;

run;

if you need this by different groupings, then you can add that with a group by statement and then merge back onto your original data.

Brandon

Ask a Question
Discussion stats
  • 3 replies
  • 202 views
  • 0 likes
  • 4 in conversation