Help using Base SAS procedures

Formatting results of Proc Means without using ODS

Reply
Occasional Contributor
Posts: 9

Formatting results of Proc Means without using ODS

Wondering if anyone's figure out a way to format output of proc means (or other similar procedures) without using the ODS option. There are times when you just want to throw in a format statement and want to see results in a user-friendly format but it seems its not as straightforward as it sounds.

For example, let's say I wanted to get the smallest and largest date from the last-created dataset. Since the dates are stored in numeric (SAS date) format, I'd want to add on a format statement so I can actually see what those dates are. Something similar to this code:

proc means MIN MAX;

  format MY_DATE DATE9.;

  var MY_DATE;

run;

What I get is this:

Minimum Maximum 

  ---------------------------- 

  20090.00 20310.00 

  ---------------------------- 

I've tried placing the format statement both BEFORE and AFTER the var statement but haven't had luck. It seems the format statement is ignored.

Of course, I could use options like an output statement or ODS etc. etc. which seem to trigger the format statement but my whole point is why do any extra work unless its absolutely required.

Regular Contributor
Posts: 156

Re: Formatting results of Proc Means without using ODS

I once tried using PROC MEANS to do this but gave it up.  I've found PROC SQL is better suited for this type of task, IMO.

PROC SQL;
   SELECT DISTINCT Stock,
            (MIN(Date)) FORMAT=
mmddyy10. AS MIN_of_Date,
            (MAX(Date)) FORMAT=
DATE. AS MAX_of_Date
     
FROM SASHELP.STOCKS;
QUIT;
Occasional Contributor
Posts: 9

Re: Formatting results of Proc Means without using ODS

You're right @PhilC. I've turned to proc sql myself in similar situations, which works well if you have a few variables.

Proc SQL requires a format statement for each variable, whereas if the format statement worked in proc means, you could do something like this, for example:

format var1-varN comma12.;

So the benefit of having a format statement in proc means would be if you had multiple variables that you wanted to apply the same format to, you could save some typing.

Super User
Posts: 10,516

Re: Formatting results of Proc Means without using ODS

Or use another procedure that will allow specific formats for variables.

proc tabulate;

     var my_date;

     tables mydate, max*f=date9. min*f=mmddyy10.;

run;

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