BookmarkSubscribeRSS Feed
Kenny
Obsidian | Level 7
I am applying the MONYY7. format to a date field in the Summary Statistics dialog. However, it always appears in the output as MONYY5.??

It works fine in One Way Frequencies, and in other dialogs.

The code preview clearly shows the line FORMAT MYDATE MONYY7.

Any help is appreciated.
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
You are probably using the DATE variable in a CLASS statement (or else you're selecting it as the classification variable) in your task. I can duplicate your issue with code.
[pre]
data testdate;
set sashelp.prdsale;
** month IS a SAS date, but formatted to MonName3;
** so create an explicit date variable and a character date variable;
date = month;
altdate = date;
chardate = put(month,monyy7.);
format date monyy7. altdate date9.;
run;

proc print data=testdate(obs=15);
var prodtype date altdate chardate actual;
title 'proc print using formats assigned in data step';
run;

ods listing;
proc means data=testdate;
title 'compare date formats used to proc print of data';
var actual;
class date altdate;
format date monyy7. altdate date9.;
run;

proc means data=testdate;
title 'using character version of date';
var actual;
class chardate;
run;

[/pre]

But duplicating the problem doesn't really help you. The workaround that I show in my code is to create a character variable that contains the date formatted with MONYY7 and then use the character variable as the CLASS variable in your summary statistics task. Or just switch over to a code node and submit the proc means code once you create the character version of the date.

However, I think your best bet for help with this problem is to contact Tech Support. There's something odd happening and Tech Support is the best place to go for help.

To find out how to contact Tech Support, refer to:
http://support.sas.com/techsup/contact/index.html

cynthia
advoss
Quartz | Level 8
Cynthia, if you substitute proc summary with an output statement for your proc means, the class variables "respect" the formats that have been assigned. Of course, then you would need a proc print to display the results.


proc summary data=testdate nway missing;
title 'compare date formats used to proc print of data';
var actual;
class date altdate;
format date monyy7. altdate date9.;
output out=testdate1;
run;
Kenny
Obsidian | Level 7
I guess I need to report this as a bug. I'm assisting end users who are not code savvy, so I want to limit the use of code as much as possible.
Cynthia_sas
SAS Super FREQ
Hi:
I see that. It was my understanding that PROC MEANS and PROC SUMMARY were using the SAME code and the only difference was the print/noprint settings.

IF you take the output statement away from the PROC SUMMARY, then you do get the same behavior as when you use PROC MEANS:
[pre]
proc summary data=testdate print;
var actual;
class date altdate;
format date monyy7. altdate date9.;
*******output out=testdate1;
run;

[/pre]

In fact, if you put the OUTPUT statement in PROC MEANS, then you get the same results as the PROC SUMMARY with an OUTPUT
statement. I think the behavior in either case (ignoring the MONYY format) is incorrect.

So I still think that the workaround is:
1) convert the date to a character string for the CLASS variable
2) always use the OUTPUT statement with either PROC MEANS or PROC SUMMARY and then always follow it with a PROC PRINT.

But there's still the issue of "is this working as designed -- why would you NOT want to respect the format on the CLASS variable, even if the CLASS variable is numeric" -- and that's a question for Tech Support.

cynthia

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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