The SAS Output Delivery System and reporting techniques

Proc Report Month Order

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Proc Report Month Order

Hi,

 

I've been trying to sort out the order of months for a report I am creating. There is a previous thread where I have posted (https://communities.sas.com/thread/67637 ) 'Month Order' which outlines the issue in more detail. There have been some recent updates to this thread which is outlined below. 

 

I've attached 3 separate screenshots. 'Month order 2' is where the raw date variable 'UW_MTH' has been used and has produced the output 'Max Bonus Output 2'.  'Month Order 3' is where the new variable 'Date1' has been used and has returned a SAS error 'Date1 must use a character format'.  It would be preferable, to use the date1 variable because if you remove the format in the proc report, the Months in numerical form are returned and are sorted correctly in chronological order .The output for this then reads 15001 - 14335 - 14305 - 14274 which correlates to Jan15 - Dec14- Nov14 - Oct14 in descending order which is desired but it would preferable to have this in MMMYY5. form.

 

It's worth noting that the 'Date1' variable is a character type variable.

 

Would really appreciate the help,

Thanks.  

 

 

 

 

 

 


Month Order 3.JPGMonth Order 2.JPGMax Bonus Output 2.JPG

Accepted Solutions
Solution
‎02-13-2015 09:43 AM
SAS Super FREQ
Posts: 8,868

Re: Proc Report Month Order

Hi, the only other thing I can think of is the default ordering is for FORMATTED order. Usually with dates, I change ORDER=INTERNAL. When I use SASHELP.PRDSALE, as you can see from the screen shot, the months are in descending order.

Cynthia

ods html file='c:\temp\desc_month.html';

proc report data = sashelp.prdsale nowd ;

  title1 "Percentage of Max Bonus Policies sold by broker";

   Column region month,(actual predict);

   define region / group 'lead Agent';

   define month/ descending order=internal across format=monyy5.;

   define actual / analysis sum;

   define predict / analysis sum 'Max Bonus Count';

run;

ods html close;


desc_month.png

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Proc Report Month Order

Posted in reply to ToonKnight

If you insist on DATE1 for the axis variable and it is character you aren't going to make Any progress.

I strongly recommend, especially for graphing, that if you have something that is supposed to be a date make it a SAS date variable. Then you can use the SAS formats for display and in many places you have access to syntax such as interval= for ticks at year, month, week etc, or VALUES= ("01JAN08"d to "01MAY08"d by month).

Super User
Posts: 19,822

Re: Proc Report Month Order

Month Order 2.jpg shows the use of UW_MTH and format monyy5. with incorrect output?

Starting off from using UW_MTH - month order 2.jpg

1. Try sorting the data by LA_NUM_NAME UW_MTH before the process

2. Try adding order to the uw_mth line which includes descending

PS. It's much easier if you copy and paste your code here rather than include images.

Occasional Contributor
Posts: 12

Re: Proc Report Month Order

Hi,

I have tried the 2 steps above but still cannot order the months. Perhaps there is something wrong with the code outlined below;

/*Data Build*/

options symbolgen mprint merror spool errors=3;

%MACRO BUILD(PROD);

data &PROD._report;

set &PROD.mm_dm_rating_factor (keep= PT_GARAGE_CD PT_NCB_YRS NB_COUNT LA_NUM_NAME UW_MTH where=(NB_COUNT =1 and

intnx('month', today(), -1, 'e') > UW_MTH >= intnx('month', today(), -4, 'b')));

binary_garaged = put(PT_GARAGE_CD,$PT_GARAGE_CD.) = 'Vehicle Is Garaged';

date1 = put(UW_MTH, Julian5.);

put date1;

bonus = pt_ncb_yrs >= 9;

run;

Proc sort Data = &PROD._report;

by LA_NUM_NAME UW_MTH;

run;

%MEND;

%BUILD(MKS);

%BUILD(ZEN);

/*Garaged and NB reports*/

options symbogen mprint merror spool errors =3;

%MACRO BONUS(PROD);

proc report data = &PROD._report nowd headline headskip;

title1 "Percentage of Max Bonus Policies sold by broker";

Column LA_NUM_NAME UW_MTH, (NB_Count bonus bonus=bonus_pct);

define LA_NUM_NAME / group 'lead Agent';

define UW_MTH / order descending across '-Month-';

define NB_COUNT / analysis sum;

define bonus / analysis sum 'Max Bonus Count';

define bonus_pct / analysis mean format=percent9.2 '% with Max Bonus';

run;

%MEND BONUS;

%BONUS(MKS);

%BONUS(ZEN);

Super User
Posts: 19,822

Re: Proc Report Month Order

Posted in reply to ToonKnight

My only other thought is to remove the "-Month-" from the UW_Month variable.

It works absolutely fine for me with this method, so I suggest contacting Tech Support.

The following should work, from my knowledge of Proc Report:

proc report data = &PROD._report nowd headline headskip;

title1 "Percentage of Max Bonus Policies sold by broker";

Column LA_NUM_NAME UW_MTH, (NB_Count bonus bonus=bonus_pct);

define LA_NUM_NAME / group 'lead Agent';

define UW_MTH / descending across format=monyy5.;

define NB_COUNT / analysis sum;

define bonus / analysis sum 'Max Bonus Count';

define bonus_pct / analysis mean format=percent9.2 '% with Max Bonus';

run;

Solution
‎02-13-2015 09:43 AM
SAS Super FREQ
Posts: 8,868

Re: Proc Report Month Order

Hi, the only other thing I can think of is the default ordering is for FORMATTED order. Usually with dates, I change ORDER=INTERNAL. When I use SASHELP.PRDSALE, as you can see from the screen shot, the months are in descending order.

Cynthia

ods html file='c:\temp\desc_month.html';

proc report data = sashelp.prdsale nowd ;

  title1 "Percentage of Max Bonus Policies sold by broker";

   Column region month,(actual predict);

   define region / group 'lead Agent';

   define month/ descending order=internal across format=monyy5.;

   define actual / analysis sum;

   define predict / analysis sum 'Max Bonus Count';

run;

ods html close;


desc_month.png
Occasional Contributor
Posts: 12

Re: Proc Report Month Order

Posted in reply to Cynthia_sas

Thanks Cynthia,

Managed to sort the order out, using order=internal seemed to do the trick. Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1469 views
  • 3 likes
  • 4 in conversation