DATA Step, Macro, Functions and more

How to create new variables from an existing date variable in a dataset?

Reply
New Contributor
Posts: 3

How to create new variables from an existing date variable in a dataset?

Hi all,

 

I have a set of data with customer name, birth_date. I need to create a few new variables, Bday2009, BdayDOW2009 and Age2009.

How shall I write the codes?

  • Bday2009 is the combination of the month of Birth_date, the day of Birth_date and the constant of 2009 in the MDY function.
  • BdayDOW2009 is the day of week of Bday2009,
  • Age2009 is the age of the customer in 2009, Subtract Birth_date from Bday2009 and divide the result by 365.25.

 

Pardon as I am new to SAS and this is my school assignment which am now having diffculities in solving. Thanks advance for any help given.

 

 

Trusted Advisor
Posts: 1,934

Re: How to create new variables from an existing date variable in a dataset?

Show us examples of what you have tried.

New Contributor
Posts: 3

Re: How to create new variables from an existing date variable in a dataset?

Posted in reply to PaigeMiller

Hi,

 

the Birth_date is in date9, format (example; 12July1974),

i am stacked at creating the Bday2009 variables as I need to combine the day and month of birth_date with a constant year of 2009,

 

i tried:

Birth_date=myd(month,3, day,2, year,4);

year= ‘2009’;

Bday2009=day month year;

run;

 

Tried several ways but still can’t get it...

Trusted Advisor
Posts: 1,934

Re: How to create new variables from an existing date variable in a dataset?

bday2009=mdy(month(birth_date),day(birth_date),2009);
New Contributor
Posts: 3

Re: How to create new variables from an existing date variable in a dataset?

Posted in reply to PaigeMiller

Ok, will try it. Thanks for the help.

Ask a Question
Discussion stats
  • 4 replies
  • 92 views
  • 0 likes
  • 2 in conversation