BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

I'm not a big fan of SAS dates, so anyone know of a simple and quick way to fix up mixed dates in a dataset.

Have:

abc  Jan-01

abc  Feb-01

abc  01-Mar

abc  01-Apr

def  Jan-01

def  Feb-01

def  01-Mar

and so on......many many obs

Want:

abc  2001.01

abc  2001.02

abc  2001.03

abc  2001.04

def   2001.01

you get the idea...

Thanks

3 REPLIES 3
data_null__
Jade | Level 19

The ANY informats don't seem to want to read this so perhaps a user written INFORMAT will work.

proc format;

   picture monyyd(default=6) other='%b-%0y'  (datatype=date);

   picture yymond(default=6) other='%0y-%b'  (datatype=date);

   run;

     

data cntl;

   retain fmtname 'XmonyyX' type 'I' hlo 'UJ ';

   do year=2000 to 2012; * adjust as necessary;

      do month=1 to 12;

         label = mdy(month,1,year);

         start = put(label,monyyd6.);

         output;

         start = put(label,yymond6.);

         output;

         end;

      end;

   format label yyqp.;

   run;

*proc print;

   run;

proc format cntlin=cntl;

   *select @X:;

   run;

data test;

   input id:$3. cdate:$6. +(-7) date:xmonyyx.;

   format date yymmp.;

   cards;

abc  JAN-01

abc  Feb-01

abc  01-Mar

abc  01-Apr

def  Jan-01

def  Feb-01

def  01-Mar

;;;;

   run;

proc print;

   run;

Obs    id     cdate      date

1     abc    JAN-01    2001.01

2     abc    Feb-01    2001.02

3     abc    01-Mar    2001.03

4     abc    01-Apr    2001.04

5     def    Jan-01    2001.01

6     def    Feb-01    2001.02

7     def    01-Mar    2001.03

art297
Opal | Level 21

How about?:

data have (drop=dummy);

  options datestyle=myd;

  format date date9.;

  input (code dummy) ($) ;

  if anydigit(substr(dummy,1,1)) then

   dummy=catt(substr(dummy,4,3),'-',

    substr(dummy,1,2));

  date=input(dummy, anydtdte6.);

  cards;

abc  Jan-01

abc  Feb-01

abc  01-Mar

abc  01-Apr

def  Jan-01

def  Feb-01

def  01-Mar

;

podarum
Quartz | Level 8

Love it how I get anwers and learn a whole lot here.  thanks

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1259 views
  • 0 likes
  • 3 in conversation