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.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
  • 3 replies
  • 925 views
  • 4 likes
  • 3 in conversation