DATA Step, Macro, Functions and more

MONyyw.

Reply
Super Contributor
Posts: 647

MONyyw.

how to convert JAN2010 format to 01-2010?
SAS Super FREQ
Posts: 8,743

Re: MONyyw.

Hi:
Check out the MMYYx format...for example, if you have a SAS date value for today, then the MMYYd7. format would display 02-2010 for today's date. (the 'd' in the format name says to put a dash or hyphen between the month and the year.

It's not entirely clear what your question means -- the reference to MONyyw. in the subject implies that you have a SAS date variable and are already using the MONYYw. format -- in which case, switching to a different format should be easy and require nothing more than a FORMAT statement with a different format for your numeric date variable.

However, if you have a CHARACTER variable or string with the value 'JAN2010' and you need to turn that CHARACTER variable into a SAS date value, so you can use a format -- that is a different question and not so easily solved with a FORMAT statement.

cynthia

Also, it's not clear whether this question is related to this previous post:
http://support.sas.com/forums/message.jspa?messageID=50092#50092
Regular Contributor
Posts: 233

MONyyw.

PROC SQL;

SELECT DATE FORMAT MMYYS. FROM TABLE NAME;

QUIT;

Frequent Contributor
Posts: 75

Re: MONyyw.

This is pretty old, so I dare say not relevant anymore, but this is how I might have done it:

data _null_;
   date = 'JAN2010';
   format date2 mmyyd7.;
   date2 = input(date, monyy7.);

   call symput('date',  date);
   call symput('date2', date2);
run;
%put date=&date. date2=%sysfunc(putn(&date2., mmyyd7.) );

Which outputs:

20 data _null_;

21 date = 'JAN2010';

22 format date2 mmyyd7.;

23 date2 = input(date, monyy7.);

24

25 call symput('date', date);

26 call symput('date2', date2);

27 run;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).

26:25

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

28 %put date=&date. date2=%sysfunc(putn(&date2., mmyyd7.) );

date=JAN2010 date2=01-2010

Super Contributor
Posts: 1,636

Re: MONyyw.

if you have a CHARACTER variable:

data have;

input date $;

cards;

jan2012

feb2012

;

proc sql;

  create table want as select input(date,MonYY7.)

     as date format mmyyd7.

       from have;

quit;

proc print;run;

                                         Obs       date

                                           1     01-2012

                                           2     02-2012

Linlin

Ask a Question
Discussion stats
  • 4 replies
  • 313 views
  • 0 likes
  • 5 in conversation