DATA Step, Macro, Functions and more

Problem With Format.

Reply
Super Contributor
Posts: 276

Problem With Format.

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

Super User
Super User
Posts: 6,500

Re: Problem With Format.

MONNAME. formats a DATE, not a month number.

data _null_;

  x=today();

  put x monname3.;

run;

Super Contributor
Posts: 276

Re: Problem With Format.

Oh thanks Tom..

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

Thanks..

Sanjeev.K

Super Contributor
Posts: 349

Re: Problem With Format.

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

Super Contributor
Posts: 1,636

Re: Problem With Format.

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

Respected Advisor
Posts: 3,124

Re: Problem With Format.

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

Super Contributor
Posts: 1,636

Re: Problem With Format.

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

Respected Advisor
Posts: 3,124

Re: Problem With Format.

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

Ask a Question
Discussion stats
  • 7 replies
  • 385 views
  • 0 likes
  • 5 in conversation