DATA Step, Macro, Functions and more

MONNAME3.

Reply
Super Contributor
Posts: 266

MONNAME3.

data test;

input month;

format month monname3.;

datalines;

1

2

3

4

5

;

run;

Proc print data=test;

run;

when i run this code, i get result like this...

                                             Obs    month

                                              1      Jan

                                              2      Jan

                                              3      Jan

                                              4      Jan

                                              5      Jan

its sud be like

jan

feb

mar

& so on...

plz help....

thanks

Frequent Contributor
Posts: 139

Re: MONNAME3.

Hi,

Format is applied on the date value.SAS Consider this numbers as date and output the month for the data. It consider it as dates of Jan1960.

Thanks,

Manoj Bansal

Super Contributor
Posts: 266

Re: MONNAME3.

Posted in reply to manojinpec

Hi Manoj,

its working on date part not with year.. if like 1 means 1st date of year n i will work till 365.like if i give 31st then it returns feb, but jan is a 31 days month. 60 give mar.

it cant b use with date.

so how can i use monname3.

Frequent Contributor
Posts: 139

Re: MONNAME3.

Please note that 01jan1960 is 0. So 31 would be 01 feb 1960. that is why it is giving feb. 60 would give mar only. as 60 would be march date.

Super Contributor
Posts: 266

Re: MONNAME3.

Posted in reply to manojinpec

jan belongs to 31 days...apart it my question is how can i use monname3. format?

there is a dataset name sashelp.prdsales. in that column name month having format monname3.  plz check

Super Contributor
Posts: 345

Re: MONNAME3.

From the documentation:

The common ground that SAS uses to represent dates is called a SAS date value. No matter which form you use to write a date, SAS can convert and store that date as the number of days between January 1, 1960, and the date that you enter.

(Step-by-Step Programming with Base SAS(R) Software)

The column "month" in sashelp.prdsales contains full date numbers, so if you change the format of "month" to date9. full dates are displayed.

proc print data=sashelp.prdsale;

    format month date9.;

run;

Using sas formats is the common way associating numbers with names/text.

Super Contributor
Posts: 276

Re: MONNAME3.

Hi...

MONNAME. formats a DATE, not a month number.


Monname format writes date values as name of the month,but your 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.

If you don't want to create User defined Format.Here is the Alternative.But i strongly recommend to use user defind format.

data test(Drop=Month);

format month1 monname3.;

input month;

month1=mdy(month,1,2013);

datalines;

1

2

3

4

5

;

run;

Proc print;

run;

Thanks &Regards.

Sanjeev.K

Contributor
Posts: 70

Re: MONNAME3.

You can use below code..this is very easy to use ..

proc format;

value mon  1 = JAN

           2 = FEB

    3 = MAR

    4 = APR

    5 = MAY

    ;

    run;

data test;

input month;

format month mon.;

datalines;

1

2

3

4

5

;

run;

Proc print;

run;

Thanks,

Yaswanth

New Contributor
Posts: 4

Re: MONNAME3.

The result is correct because the format monname3. only works with sas date value and not with the month value.

try this to see the difference:

data _null_;

call symputx('_month',put(date(),monname3.));

put "&_month." ;

call symputx('_month2',month(date()));

put "&_month2." ;

call symputx('_month3',put(month(date()),monname3.));

put "&_month3." ;

run;

Regards,

Carlos S

Ask a Question
Discussion stats
  • 8 replies
  • 2218 views
  • 1 like
  • 6 in conversation