BookmarkSubscribeRSS Feed
BecomingSASsy
Calcite | Level 5

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.

3 REPLIES 3
PhilC
Rhodochrosite | Level 12

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;
BecomingSASsy
Calcite | Level 5

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.

ballardw
Super User

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;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 830 views
  • 4 likes
  • 3 in conversation