BookmarkSubscribeRSS Feed
Vigneswar
Obsidian | Level 7

Hi folks,

 

I'm trying to find age of customer by using a column which has Julian date as the date of birth.

 

Below is my input,

 

customer_dob = 92138

changed_dt = 17-05-1992

 

dob = intck('year',today,changed_dt);

 

I want to know a way to get the changed_dt in the above format stored as a numeric.

 

any thoughts??

10 REPLIES 10
Vigneswar
Obsidian | Level 7

Hi folks,

 

I'm trying to find age of customer by using a column which has Julian date as the date of birth.

 

Below is my input,

 

customer_dob = 92138

changed_dt = 17-05-1992

 

dob = intck('year',today,changed_dt);

 

I want to know a way to get the changed_dt in the above format stored as a numeric.

 

any thoughts??

Patrick
Opal | Level 21

Bit guessing what you're really asking for. Is below doing what you need? If so then shouldn't be an issue to use such syntax in DS2.

data have;
  customer_dob_jul = 92138;
  customer_dob_sas = datejul(customer_dob_jul);
  age=yrdif(datejul(customer_dob_jul),today(),'age');
  format customer_dob_sas date9.;
run;

Patrick_0-1624540188602.png

 

Patrick
Opal | Level 21

The datejul() function converts Julian to a SAS Date value

datejul(customer_dob_jul);

 

ballardw
Super User

Is customer_dob a character or numeric variable?

If character

changed_dt = input(customer_dob , julian5.);

If numeric and always 5 digits:

changed_dt = input(put(customer_dob,z5.) , julian5.);

The input function requires character input so if the value is numeric you need to create a character value. The z5 would be needed to place a leading zero if the "year" was 2000 to 2009 where the year component would be 00 to 09 and SAS numerics do not internally store leading zeroes.

If your customer_dob has a mix of 7 and "5" digits, i.e. some of the years are 1992 and others are 92 you will have to examine the value and decide whether to use Julian5 or Julian7 as the informat in the Input function.

Or go back to where the data was read into SAS and use a data step to read the data and set the proper Julian informat from the beginning.

 

Then assign a format to changed_dt with : format changed_dt ddmmyyd10. ;

so the default display will be as you show. The last d sets a hyphen as the separator between day, month and year.

 

You need to use today() with the () to use the function. If you don't you'll likely get warnings about uninitialized variable Today.

 

Vigneswar
Obsidian | Level 7
Thanks for the reply...

input statement is not working in DS2 code.

Let's take my input is 1992-05-17 stored as numeric (from source).

I want to calculate the age of each customer.
Kurt_Bremser
Super User

Please supply your incoming dataset as code, in a data step with datalines. Only then can we be sure about variable atttributes and contents. Right now I have no idea at all if your variables are in fact numeric or character.

If you're not sure about dataset metadata, run a PROC CONTENTS and show us the definitions of the variables you work with.

Tom
Super User Tom
Super User

@Vigneswar wrote:

Let's take my input is 1992-05-17 stored as numeric (from source).
.

What does that mean?  1992-05-17 is not a number.  Numbers do not have hyphens in them.

Do you have a numeric variable with the YYMMDD10. format attached to it?  So the number 11,825 is stored in the variable.  

Is it numeric with some datetime format attached to it?  So that the value is actually somewhere between 1,021,680,000
and 1,021,766,400?
Or is it a character variable?

ballardw
Super User

@Vigneswar wrote:
Thanks for the reply...

input statement is not working in DS2 code.

Let's take my input is 1992-05-17 stored as numeric (from source).

I want to calculate the age of each customer.

Your question did not mention DS2 in any form.

 

1992-05-17 is not in any way a number so I am not sure how it can be "stored as a number".

 

Since DS2 usually means connecting to a an external data source you likely need to tell us which source. Depending on that source and the actual values stored you may be looking for the date and time conversion functions such as TO_DOUBLE or TO_DATE.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 10 replies
  • 1668 views
  • 1 like
  • 5 in conversation