Sample 24651: Generate the month name from a numeric value
The sample code on the Full Code tab illustrates how to create a new variable whose value is a month name.
Note:
If your numeric variable is a SAS date value (the number of days since January 1, 1960), you can use the MONNAMEw. format to either display the SAS date as its month name or create a new variable using the PUT function. See Sample 1.
If you have a numeric variable with values 1-12, you will need a user-defined format. See Sample 2.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Sample 1 : MONNAME format with a SAS date value */
data _null_;
input date :mmddyy8.;
/* Create a new variable */
month_name=PUT(date,monname.);
put month_name= @;
/* or just format the date */
put @25 date @35 date monname.;
datalines;
01/15/04
02/29/04
07/04/04
08/18/04
12/31/04
;
run;
/* Sample 2: Numeric value 1-12 with user-defined format */
proc format ;
value mn_name 1='January'
2='February'
3='March'
4='April'
5='May'
6='June'
7='July'
8='August'
9='September'
10='October'
11='November'
12='December'
other='Invalid';
run;
data test2;
input num;
format num mn_name.;
datalines;
1
3
8
10
0
;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
OUTPUT to SAS log -- Sample 1 : MONNAME format with a SAS date value
month_name=January 16085 January
month_name=February 16130 February
month_name=July 16256 July
month_name=August 16301 August
month_name=December 16436 December
RESULTS -- Sample 2: Numeric value 1-12 with user-defined format
Obs num
1 January
2 March
3 August
4 October
5 Invalid
Create a new variable whose value is a month name.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step
|
Date Modified: | 2005-12-16 03:02:56 |
Date Created: | 2004-09-30 14:09:01 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |