Hi SAS Forum,
I wanted to convert these 3 date-related variables in the attached sas data set into date9. format.
I tried this code with datepart function but an error messege pops up.
data want;
set J.have;
format Date_cancel date9. ;
format Date_of_firs_deposit date9.;
format Account_date date9.;
Date_cancel =datepart(Date_cancel);
Date_of_firs_deposit= datepart (Date_of_firs_deposit);
Account_date = datepart (Account_date);
run;
Error messege comes like this.
15 data want;
16 set J.have;
17 format Date_cancel date9. ;
18 format Date_of_firs_deposit date9.;
19 format Account_date date9.;
______
484
NOTE 484-185: Format $DATE was not found or could not be loaded.
20 Date_cancel=datepart(Date_cancel);
21 Date_of_firs_deposit= datepart (Date_of_firs_deposit);
22 Account_date= datepart (Account_date);
23 run;
Could anyone please help me?
Thanks
Mirisage
Hi,
Your account_date is a character variable. try the code below:
data want;
set j.have;
Date_cancel =datepart(Date_cancel);
Date_of_firs_deposit= datepart(Date_of_firs_deposit);
_Account_date = input(scan(Account_date,1,' '),ddmmyy10.);
format Date_cancel Date_of_firs_deposit _Account_date date9.;
run;
proc print;
var _:;
run;
Hi,
Your account_date is a character variable. try the code below:
data want;
set j.have;
Date_cancel =datepart(Date_cancel);
Date_of_firs_deposit= datepart(Date_of_firs_deposit);
_Account_date = input(scan(Account_date,1,' '),ddmmyy10.);
format Date_cancel Date_of_firs_deposit _Account_date date9.;
run;
proc print;
var _:;
run;
Hi Linlin,
Many thanks. Your code works well.
Now only I realized the variable “Account_date” was a character variable and then it has to be treated differently.
Its format was like below.
31/12/2010 0:00:00
31/7/2010 0:00:00
28/2/2011 0:00:00
This means DD/MM/YYYY and then “time” (I do not know how to write the time format)
Question 1:
In your code below, the informat was written as ddmmyy10. But it should have been ddmmyyyy10. as shown in yellow above. But it works. How come it worked? Could you please let me know time permitting?
data want;
set H.have;
Date_cancel =datepart(Date_cancel);
Date_of_firs_deposit= datepart(Date_of_firs_deposit);
_Account_date = input(scan(Account_date,1,' '),ddmmyy10.);
format Date_cancel Date_of_firs_deposit _Account_date date9.;
run;
proc print;
var _:;
run;
Question 2:
I had an “account_date” character variable in another data set the form 5/23/2011 0:00:00
Then I have included informat as mmddyy10. and it also worked. But it shuould have been written in the code as mmddyyyy10.
How come my one also worked?
Thank you for your time.
Mirisage
DDMMYY and MMDDYY are names of formats. The 10 on the end specifies the length, ie how many characters are written. As only 8 characters are needed for the date information, the remaining 2 characters are used for delimiters, slashes in this case.
Regards
Richard in Oz
Afterthought
You may be expecting SAS format names to be like formats in Excel and some other languages where the "name" is really a template that specifies where data elements are placed, and any punctuation. But you cans see from a SAS format name like DATE (as in DATE9.) where the result is like 24OCT2012 that SAS format names are not templates.
Hi Richard,
I am curious what does "Oz" stand for?:smileysilly: Thank you!
I am a New Zealander (Kiwi) living and working in Australia (Local nickname: Oz). Nothing to do with being a wizard.
Richard in Oz
Hi Richard in Oz and Linilin,
Thank both of you very much for this elaboration.
Now I am very much clear that SAS format names are not templates.
Also good to know Oz stands for Aussie.
Regards
Mirisage
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.