Exploring, modeling, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

About getting the max date in a table field

Reply
Frequent Contributor
Posts: 77

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

Grand Advisor
Posts: 9,748

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.

Frequent Contributor
Posts: 77

Re: About getting the max date in a table field

fecha_ingreso is a date field (datetime)

Snap 2015-04-27 at 13.24.06.jpg

SAS Super FREQ
Posts: 275

Re: About getting the max date in a table field

I think what Silvia is trying to do is this:

max.png

The Max operator expects a measure rather than a date.

SAS Super FREQ
Posts: 275

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.

Regular Contributor
Posts: 196

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

Frequent Contributor
Posts: 77

Re: About getting the max date in a table field

thanks Teja!.

Frequent Contributor
Posts: 77

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

Contributor
Posts: 59

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?

 

 

Frequent Contributor
Posts: 75

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

dateranker.GIF

 

then

rank.GIF

 

date table.GIF

 

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.

Post a Question
Discussion Stats
  • 9 replies
  • 1539 views
  • 1 like
  • 6 in conversation