Help using Base SAS procedures

'Transform' date in Sas-format

Reply
New Contributor
Posts: 2

'Transform' date in Sas-format

Hi,

I have dates in the following form: jjjmm (200405, 200602,...). I have 12.000 variables and the dates vary from 199907 - 200612. I was wondering how to 'transform' these dates into the Sas-format, that allows me to calculate with the date? (I want to calculte the average time).

I have seen a few examples, but I was wondering how I can do this for all the different dates (and not for one specific date).

I hope someone can help me...
Super Contributor
Super Contributor
Posts: 365

Re: 'Transform' date in Sas-format

Hello Laura,

This is a solution for cases when your date is a numberical variable and character variable:
[pre]
data i;
YourDate=200405; YourDat="200405"; output;
YourDate=200602; YourDat="200602"; output;
run;
data r;
set i;
date=MDY(MOD(YourDate,100),01,INT(YourDate/100));
format date date7.;
YD=input(YourDat,6.);
dat=MDY(MOD(YD,100),01,INT(YD/100));
format dat date7.;
run;
[/pre]
Sincerely,
SPR Message was edited by: SPR
Super User
Posts: 11,343

Re: 'Transform' date in Sas-format

Or if you are reading from an external text file or data lines use the INFORMAT YYMMN6.

data test;
informat date yymmn6.;
input date;
format date mmddyy10.;
datalines;
200405
200505
200507
200610
;
run;
proc print; run;
New Contributor
Posts: 2

Re: 'Transform' date in Sas-format

Thanks a lot for your help!!
Ask a Question
Discussion stats
  • 3 replies
  • 107 views
  • 0 likes
  • 3 in conversation