Desktop productivity for business analysts and programmers

Month Order

Reply
Occasional Contributor
Posts: 12

Month Order

Hi,

I'm generating a report using proc report to output data split by month. The issue that I'm currently having is sorting the months across in order. There are 2 attachments, one to represent the code and the other which conveys the output. For the output, my initial assumption is that this has something to do with the first row where there are no values. I have tried to remedy this but unfortunately to no avail.

Would really appreciate any help on the matter if possible.

Thanks




Max Bonus Output.JPGMonth Order.JPG
Super User
Posts: 19,150

Re: Month Order

Don't create Month as a text variable. Use the date value and format it in the report. Otherwise SAS will at best order it alphabetically.

Super User
Posts: 9,867

Re: Month Order

Better don't use character Date .  and you padding blanks before them to get the order you want by proc format or override its value.

proc format;

value $x

'DEC2014'='    DEC2014' ;

run;

then add this format at proc report .

Xia Keshan

Occasional Contributor
Posts: 12

Re: Month Order

I've managed to get my final output in the right order, but cannot format the 'date1' variable to get in the form mmmyy(i.e. DEC14 etc...). For instance, I've added the lines of code below which has managed to sort them in order but not in 'mmmyy' form. I've tried to format this in the proc report using 'Format = mmmyy5.' in the define statement however this returns an error 'variable date1 must use character variable'.

/*Data Build*/

date1 = put(UW_MTH, Julian5.);

put date1;

/*Proc report section*/

define Date1 / descending across ' - Month -'

Thanks

Super User
Posts: 19,150

Re: Month Order

Does something like this work:

*Instead use the raw variable and format it here:

/*Proc report section*/

define UW_MTH / descending across ' - Month -' format=monyy5.;

Occasional Contributor
Posts: 12

Re: Month Order

Hi,

Sorry the question remains unanswered, not sure what happened, so please ignore the above.

I've tried using the raw variable in the proc report section it just outputs the same issue  as previous where the months are not in order.

The date1 variable is a character variable (with the month values now in numerical from). Would I need to convert character type to date type to eliminate the Sas error as stated above?

Thanks

Super User
Posts: 19,150

Re: Month Order

Post this in ODS Reporting and perhaps can help.  

Super User
Posts: 19,150

Re: Month Order

It works on this absolutely useless report:

proc report data=sashelp.stocks;

columns stock date;

define stock/group;

define date/across descending format=year4.;

run;

Make sure to post your full code and sample data, perhaps something else is the issue.

Occasional Contributor
Posts: 12

Re: Month Order

Hi,

I've posted this original discussion in a new thread named 'Proc Report Month Order' under ODS and Base Reporting, with additional material.

If you could have a look then it would be greatly appreciated,

Thanks.

Ask a Question
Discussion stats
  • 8 replies
  • 551 views
  • 6 likes
  • 3 in conversation