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!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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