BookmarkSubscribeRSS Feed
yaswoman
Calcite | Level 5
Hi can someone please tell me how I can do a PROC MEANS min max on a date value to find the lowest date and the higest date.

My code:
PROC MEANS DATA = temp.ms_trans MIN MAX;
VAR efectv_dt;
RUN;

The informat and format of the variable is DATE9.

I am getting

CUST_ID 08:54 Thursday, March 17, 2011 217
The MEANS Procedure

Analysis Variable : EFECTV_DT EFECTV_DT

Minimum Maximum
----------------------------
18322.00 18686.00
----------------------------

thanks so much for any input.
7 REPLIES 7
Reeza
Super User
I don't know how to do it with proc means directly but what about outputting it to a dataset and printing it or using proc sql?

[pre]
proc means data=temp.ms_trans noprint;
var efectv_dt;
output out=sample min=min_date max=max_date;
run;

proc print;
run;

OR

proc sql;
select max(efectv_dt) as max_date, min(efectv_dt) as min_date
from temp.ms_trans;
quit;

[/pre]
yaswoman
Calcite | Level 5
Thank You so much, will try that,
Reeza
Super User
It is a friday afternoon...for the sql statement also need a format,
format=date9.

proc sql;
select max(date) as max_date format =date9., min(date) as min_date format =date9.
from sashelp.stocks;
quit;
yaswoman
Calcite | Level 5
Yes I realized that, so I did add that + an create statement that would let me print.
thanks so much for your help.
data_null__
Jade | Level 19
If you create an output data set with MEANS/SUMMARY the MIN and MAX will inherit the associated format.

[pre]
data test;
do date = today() to today()+10;
output;
end;
format date date9.;
run;
proc summary data=test;
var date;
output out=mm min=min max=max;
run;
proc contents varnum;
run;
proc print;
run;


Variables in Creation Order

# Variable Type Len Format

1 _TYPE_ Num 8
2 _FREQ_ Num 8
3 min Num 8 DATE9.
4 max Num 8 DATE9.


[/pre]
yaswoman
Calcite | Level 5
Sorry I am not quite sure I understand what exactly that means.
the MIN and MAX will inherit the associated format.

thanks
data_null__
Jade | Level 19
The format associated with the analysis variable will also be associated with the statistics, MIN and MAX.

RTM

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 8491 views
  • 0 likes
  • 3 in conversation