BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Barkat
Pyrite | Level 9

I have the following dataset.

data have;
informat Month mmddyy8.;
input ID Group $ Month    ;
Format Month mmddyy8.;
cards;
01 A 12/03/22
02 A 11/03/22 
03 B 12/17/22
04 A 10/17/22 
05 B 09/24/22
06 B 12/24/22
07 C 10/24/22 
08 A 12/31/22
09 A 01/14/23
10 B 02/14/23
11 A 02/21/23
12 A 03/21/23
13 A 04/14/23
14 C 03/14/23 
15 A 01/21/23
16 C 04/21/23
17 A 02/14/23
18 C 01/14/23 
19 B 03/21/23
20 C 01/21/23
;

I would like to create a report with two columns only. Month and number. Months as Dec2022, Jan2023, Feb2023 etc. The report will have the months in correct order in the month column (not alphabetic order).

 

I tried the following but did not work.

proc report data=have;
column month n;
define month / group format=monyyyy.;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The log from your code shows:

 

6694  proc report data=have;
6695  column month n;
6696  define month / group format=monyyyy.;
ERROR: The format MONYYYY was not found or could not be loaded.
6697  run;

 

So, you should not get any PROC REPORT output. However, this does not match your subject line ... I suspect you have not shown us the actual code you are using. Please from now on, show us the actual code used.

 

The fix for months out of order, to force PROC REPORT to use the months in order, is

define month / group format=monyy. order=internal;

 


Without ORDER=INTERNAL, SAS puts things in alphabetical order, meaning April is the first month, and usually people don't want that. Using ORDER=INTERNAL, SAS puts things in numerical order, and since month is a numeric variable, SEP22 comes before APR23, the order is what people expect.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

The log from your code shows:

 

6694  proc report data=have;
6695  column month n;
6696  define month / group format=monyyyy.;
ERROR: The format MONYYYY was not found or could not be loaded.
6697  run;

 

So, you should not get any PROC REPORT output. However, this does not match your subject line ... I suspect you have not shown us the actual code you are using. Please from now on, show us the actual code used.

 

The fix for months out of order, to force PROC REPORT to use the months in order, is

define month / group format=monyy. order=internal;

 


Without ORDER=INTERNAL, SAS puts things in alphabetical order, meaning April is the first month, and usually people don't want that. Using ORDER=INTERNAL, SAS puts things in numerical order, and since month is a numeric variable, SEP22 comes before APR23, the order is what people expect.

--
Paige Miller
Barkat
Pyrite | Level 9
Excellent! Thanks a lot!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 417 views
  • 1 like
  • 2 in conversation