08-11-2015 04:01 PM
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.;
What I get is this:
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.
08-13-2015 01:18 PM
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.
08-17-2015 03:38 PM
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.