Help using Base SAS procedures

proc means

Reply
Occasional Contributor
Posts: 15

proc means

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.
Super User
Posts: 19,768

Re: proc means

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]
Occasional Contributor
Posts: 15

Re: proc means

Thank You so much, will try that,
Super User
Posts: 19,768

Re: proc means

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;
Occasional Contributor
Posts: 15

Re: proc means

Yes I realized that, so I did add that + an create statement that would let me print.
thanks so much for your help.
Respected Advisor
Posts: 3,799

Re: proc means

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]
Occasional Contributor
Posts: 15

Re: proc means

Posted in reply to data_null__
Sorry I am not quite sure I understand what exactly that means.
the MIN and MAX will inherit the associated format.

thanks
Respected Advisor
Posts: 3,799

Re: proc means

The format associated with the analysis variable will also be associated with the statistics, MIN and MAX.

RTM
Ask a Question
Discussion stats
  • 7 replies
  • 2660 views
  • 0 likes
  • 3 in conversation