Help using Base SAS procedures

Why this date variables are not converted into date9. format using datepart function ?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

Why this date variables are not converted into date9. format using datepart function ?

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

Attachment

Accepted Solutions
Solution
‎10-23-2012 04:58 PM
Super Contributor
Posts: 1,636

Re: Why this date variables are not converted into date9. format using datepart function ?

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;

View solution in original post


All Replies
Solution
‎10-23-2012 04:58 PM
Super Contributor
Posts: 1,636

Re: Why this date variables are not converted into date9. format using datepart function ?

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;

Super Contributor
Posts: 338

Re: Why this date variables are not converted into date9. format using datepart function ?

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

Super Contributor
Posts: 644

Re: Why this date variables are not converted into date9. format using datepart function ?

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

Super Contributor
Posts: 644

Re: Why this date variables are not converted into date9. format using datepart function ?

Posted in reply to RichardinOz

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.

Super Contributor
Posts: 1,636

Re: Why this date variables are not converted into date9. format using datepart function ?

Posted in reply to RichardinOz

Hi Richard,

I am curious what does "Oz" stand for?:smileysilly:  Thank you!

Super Contributor
Posts: 644

Re: Why this date variables are not converted into date9. format using datepart function ?

I am a New Zealander (Kiwi) living and working in Australia (Local nickname: Oz).  Nothing to do with being a wizard.

Richard in Oz

Super Contributor
Posts: 338

Re: Why this date variables are not converted into date9. format using datepart function ?

Posted in reply to RichardinOz

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 7511 views
  • 8 likes
  • 3 in conversation