DATA Step, Macro, Functions and more

Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

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)

 

 

 

 


Accepted Solutions
Solution
‎04-01-2018 02:26 PM
Super User
Posts: 8,216

Re: Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

Posted in reply to lglovenish96

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


All Replies
Solution
‎04-01-2018 02:26 PM
Super User
Posts: 8,216

Re: Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

Posted in reply to lglovenish96

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

 

Occasional Contributor
Posts: 6

Re: Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

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

Super User
Super User
Posts: 8,279

Re: Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

[ Edited ]
Posted in reply to lglovenish96

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
Occasional Contributor
Posts: 6

Re: Formats Monname. and Weekday. showing wrong Month name and weekday respectively.

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 316 views
  • 0 likes
  • 3 in conversation