BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TMiller16
Fluorite | Level 6

I am trying to use this and not getting anywhere.  Any help on how to use this would be appreciated.

 

I am using MONTH(tbl.field_name) to pull the month out i.e.... 1, 2, 3 etc... 12

 

Then I was using MONNAME to get the desired result 1 = January

 

Here is the code that I am using now:

 

SELECT (MONTH(t2.Sale_Date)) LENGTH=9 LABEL="Sale_Month" AS Sale_Month,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You don't need to convert anything, if your variable is a SAS date.

 

data sample;
	date_var='01Nov2016'd;
	format date_var date9.;
	month_name=put(date_var, monname.);
run;

proc print ;
run;

View solution in original post

9 REPLIES 9
GreggB
Pyrite | Level 9

What do the values of sale_date look like? Are they character or numeric?

TMiller16
Fluorite | Level 6
I do not have it specified..... should I have it as a char?
GreggB
Pyrite | Level 9

The values need to be a SAS date value, which is numeric, in order to use the MONTH function.

TMiller16
Fluorite | Level 6
ok, so I will make it numeric, and as Reeza stated it is not a function, so I think with changing the value to numeric and using the format that should work. Reeza, there are multiple months, I am not using the year.
TMiller16
Fluorite | Level 6
Thank you as well GreggB, I will make these changes and see if that solves my problem.
Reeza
Super User

Monname requires a date variable and I believe it's a format, not a function. 

 

Do do you have multiple years? 

Is January 2016= Jan 2015 = January? 

 

Select date_variable format=monname.,

put(date_variable, monname.) as new month

from ....

Shmuel
Garnet | Level 18

MONNAME is unknown function in SAS;

 

There are several methods to get month name:

1) create a format like:

       proc format lib=work;

           value monname

               1 = "January"

               2 = "February"

              ...

              12 = "December"

        ; run;

 

  then, in your datastep use: month_name = put(month(date), monname.);

 

2) Alternatively use select statemnet to creat the month_name variable:

         data want

           set have;

                 mon = month(date);

                 select (mon);

                    when (1) month_name = 'January';

                    when(2) month_name = 'February';

                   ...

                   when (12) month_name = 'December';

                   otherwise month_name = 'Invalid Date';

               end;

        run;

 

Reeza
Super User

You don't need to convert anything, if your variable is a SAS date.

 

data sample;
	date_var='01Nov2016'd;
	format date_var date9.;
	month_name=put(date_var, monname.);
run;

proc print ;
run;
JTab
Calcite | Level 5

Your post helped and it could be made even simpler:

 

proc sql;

   create table   mytablename  as

  select  

       choose_your_variables,

       put(date_variable,monname.)  as  MonthNameColumn

  from   libref.table

;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 9 replies
  • 62865 views
  • 5 likes
  • 5 in conversation