BookmarkSubscribeRSS Feed
Aman4SAS
Obsidian | Level 7

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

8 REPLIES 8
manojinpec
Obsidian | Level 7

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

Aman4SAS
Obsidian | Level 7

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.

manojinpec
Obsidian | Level 7

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.

Aman4SAS
Obsidian | Level 7

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

andreas_lds
Jade | Level 19

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.

kuridisanjeev
Quartz | Level 8

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

yaswanthj
Fluorite | Level 6

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

CarlosSantos
Calcite | Level 5

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 7303 views
  • 2 likes
  • 6 in conversation