Quartz | Level 8

## About getting the max date in a table field

Hi, I've got a date field in my table and I need to get the most recent date in it.

I'm working in SAS VA 7.1 and tried creating an item field using the MAX function but gives me error.

any idea how can I get the max date ?

thanks.

Silvia

9 REPLIES 9
Super User

## Re: About getting the max date in a table field

Show use what you did and the error.

Also, make sure your dates are SAS date values and not a character variable that looks like a date.

Quartz | Level 8

## Re: About getting the max date in a table field

fecha_ingreso is a date field (datetime)

SAS Super FREQ

## Re: About getting the max date in a table field

I think what Silvia is trying to do is this:

The Max operator expects a measure rather than a date.

SAS Super FREQ

## Re: About getting the max date in a table field

If you just want to display the most recent date in a table, the simplest solution is to sort a table in descending order by your date column.

I don't think there is an easy way in the VA expression syntax to calculate the most recent date.

You can use the TreatAs operator in a calculated measure to convert the date into a numeric, and then create an aggregated measure using the Max() operator on that calculated item. This will give you the most recent date, but the date is no longer in date form. It will look like this: 19833.

Lapis Lazuli | Level 10

## Re: About getting the max date in a table field

Hi Silvia,

If you want to show Max date in VA, you have to create Max date column in SAS table using MAX function.

As per sam you can Calculate Max date using calculated items(Treat As) and Aggregated Measures(_Max_). but the result will be in sas days.

Regards,

Teja Surapaneni

Quartz | Level 8

thanks Teja!.

Quartz | Level 8

## Re: About getting the max date in a table field

Thanks SAm!

As a quick solution I did what you are suggesting, I made a ranking.

I 'll try  the TreatAs operator.

Greetings.

Silvia

Quartz | Level 8

## Re: About getting the max date in a table field

so what is the final solution of showing the MAX(Date)

i can do the treat as and max and get a result.

how do i get that back to a date?

Pyrite | Level 9

## Re: About getting the max date in a table field

If you want top see the date in a table

• use the treat as function to create a numeric version
• create a top 1 rank on the numeric version but put the actual date value into the table

then

In the example above I have a second column showing when the data was refereshed by sas, to do this I just added column in my underlying data query which inserts todays date against every row.

Discussion stats
• 9 replies
• 10248 views
• 1 like
• 6 in conversation