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

Hey, i have been converting the months and weekdays in SAS University Edition from Numeric Value to their respective Names.

While i was converting the Month into the name of the month using the Monname. format, the format was unable to convert it month into anything other than January. For any month, the numeric value shown by the variable is correct (Example :- 4 for April), but when the format monname. is used, it shows January in the results.

Also, the weekday. format used shows wrong month when used in the above program.

The code used is as follows:-

 

options yearcutoff =1920;

data date;
format WDAY downame.
Dmon Monname.;

WDAY =weekday(today());
DMON = Month(today());
DMON_int = Month(today());
DDAy = day(Today());
Yrr = Year(today());

run;
proc print data=date;
var WDAY -- Yrr;
Run;

 

PS - Today is Sunday, 1st April 2018. 

This program is being Run on IST Time Zone.(if it helps)

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Both downame and monname formats work on SAS dates. Try:

options yearcutoff =1920;

data date;
format WDAY downame.
Dmon Monname.;

/* WDAY =weekday(today()); */
WDAY =today();
/* DMON = Month(today()); */
DMON = today();
DMON_int = Month(today());
DDAy = day(Today());
Yrr = Year(today());

run;
proc print data=date;
var WDAY -- Yrr;
Run;

Art, CEO, AnalystFinder.com

 

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

Both downame and monname formats work on SAS dates. Try:

options yearcutoff =1920;

data date;
format WDAY downame.
Dmon Monname.;

/* WDAY =weekday(today()); */
WDAY =today();
/* DMON = Month(today()); */
DMON = today();
DMON_int = Month(today());
DDAy = day(Today());
Yrr = Year(today());

run;
proc print data=date;
var WDAY -- Yrr;
Run;

Art, CEO, AnalystFinder.com

 

lglovenish96
Calcite | Level 5

@art297 I see what i was doing wrong. Thank You very much. 

Tom
Super User Tom
Super User

They show January because the numbers 1 to 12 represent the dates of 02JAN1960 to 13JAN1960.

data _null_;
 do month=1 to 12 ;
   date=mdy(month,1,2018);
   put month=z2. month date9. +1 month monname.-l month weekday.
    +5 date=comma6. date date9. +1 date monname.-l +1 date weekday. 
   ;
 end;
run;
month=01 02JAN1960 January  7     date=21,185 01JAN2018 January   2
month=02 03JAN1960 January  1     date=21,216 01FEB2018 February  5
month=03 04JAN1960 January  2     date=21,244 01MAR2018 March     5
month=04 05JAN1960 January  3     date=21,275 01APR2018 April     1
month=05 06JAN1960 January  4     date=21,305 01MAY2018 May       3
month=06 07JAN1960 January  5     date=21,336 01JUN2018 June      6
month=07 08JAN1960 January  6     date=21,366 01JUL2018 July      1
month=08 09JAN1960 January  7     date=21,397 01AUG2018 August    4
month=09 10JAN1960 January  1     date=21,428 01SEP2018 September 7
month=10 11JAN1960 January  2     date=21,458 01OCT2018 October   2
month=11 12JAN1960 January  3     date=21,489 01NOV2018 November  5
month=12 13JAN1960 January  4     date=21,519 01DEC2018 December  7
lglovenish96
Calcite | Level 5

i was getting confused with the values of days and months. Thanks for your help @Tom. 🙂 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 3958 views
  • 0 likes
  • 3 in conversation