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??
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??
Duplicate posts combined.
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;
The datejul() function converts Julian to a SAS Date value
datejul(customer_dob_jul);
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.
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.
@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?
@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.
@Vigneswar wrote:
Thanks for the reply...
input statement is not working in DS2 code.
Use INPUTC and INPUTN instead, which are available in DS2.
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 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.
Ready to level-up your skills? Choose your own adventure.