- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do the values of sale_date look like? Are they character or numeric?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The values need to be a SAS date value, which is numeric, in order to use the MONTH function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;