BookmarkSubscribeRSS Feed
kuridisanjeev
Quartz | Level 8

Hi..

I am trying to use Monname3. format in my program but it is not working properly.

Here i am giving small example..

data test;

format month monname3.;

input month amount;

cards;

9 1500

2 8200

3 3256

4 7412

5 2125

6 2536

;

run;

If i run this code i am getting output like this..

                                     Obs    month    amount

                                        1      Jan      1500

                                        2      Jan      8200

                                        3      Jan      3256

                                        4      Jan      7412

                                        5      Jan      2125

                                        6      Jan      2536

It is showing every month as Jan...

any one could you please help me in that...

Regards..

Sanjeev.K

7 REPLIES 7
Tom
Super User Tom
Super User

MONNAME. formats a DATE, not a month number.

data _null_;

  x=today();

  put x monname3.;

run;

kuridisanjeev
Quartz | Level 8

Oh thanks Tom..

Is there any way to display month names instead of number in my above example(Except PROC FORMAT)???

Thanks..

Sanjeev.K

shivas
Pyrite | Level 9

Hi,

I guess Monname format writes date values as name of the month,but you data don't have any date column.

If your data comes in the same format as you have mentioned then you can define user defined format and then apply on the month variable.

Thanks,

Shiva

Linlin
Lapis Lazuli | Level 10

data test(drop=mon);

format month monname3.;

input mon amount;

month=mdy(mon,1,2012);

cards;

9 1500

2 8200

3 3256

4 7412

5 2125

6 2536

;

run;

proc print;run;

                          Obs    month    amount

                               1      Sep      1500

                               2      Feb      8200

                               3      Mar      3256

                               4      Apr      7412

                               5      May      2125

                               6      Jun      2536

Haikuo
Onyx | Level 15

Well, I hardly disagree with LinLin, but this time will be an exception. I don't feel comfortable that her code actually made a change to your data, not just the format, I am not sure if that is exactly what you want. It will work if just for the report purpose, otherwise, you need to make your own format for it,luckily we only have 12 month, so it is not too bad:

proc format;

value mon

      1='Jan'

      2='Feb'

      3='Mar'

      4='Apr'

      5='May'

      6='Jun'

      7='Jul'

      8='Aug'

      9='Sep'

      10='Oct'

      11='Nov'

      12='Dec';

run;

data test;

format month mon3.;

input month amount;

cards;

9 1500

2 8200

3 3256

4 7412

5 2125

6 2536

;

run;

proc print;run;

Haikuo

Linlin
Lapis Lazuli | Level 10

Haikuo,

I coded that way because the OP requested:

"Is there any way to display month names instead of number in my above example(Except PROC FORMAT)???".

As your sister I strongly suggest you to edit your last post in https://communities.sas.com/message/135484#135484

Haikuo
Onyx | Level 15

My apology, I only read what I want to read.

And LOL, Thanks, Linlin, for your safty concern. as I am typing, I am hiding in a cave with my  bullet-proof vest on, hopefully it is sufficient for now.

Haikuo

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!

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
  • 7 replies
  • 1478 views
  • 0 likes
  • 5 in conversation