BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ToonKnight
Calcite | Level 5

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
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

6 REPLIES 6
ballardw
Super User

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).

Reeza
Super User

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.

ToonKnight
Calcite | Level 5

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);

Reeza
Super User

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;

Cynthia_sas
SAS Super FREQ

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
ToonKnight
Calcite | Level 5

Thanks Cynthia,

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

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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