BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

7 REPLIES 7
Linlin
Lapis Lazuli | Level 10

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;

Mirisage
Obsidian | Level 7

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

RichardinOz
Quartz | Level 8

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

RichardinOz
Quartz | Level 8

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.

Linlin
Lapis Lazuli | Level 10

Hi Richard,

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

RichardinOz
Quartz | Level 8

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

Richard in Oz

Mirisage
Obsidian | Level 7

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 12269 views
  • 8 likes
  • 3 in conversation