BookmarkSubscribeRSS Feed
Laura_BE
Calcite | Level 5
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...
3 REPLIES 3
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
ballardw
Super User
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;
Laura_BE
Calcite | Level 5
Thanks a lot for your help!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1252 views
  • 0 likes
  • 3 in conversation