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
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
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
;
Love it how I get anwers and learn a whole lot here. thanks
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.