I have a dataset that has the column:
BRTHDTC - Character
1988-02-23
1973
I am attempting to get a numerical BRTHDTC that takes the column BRTHDT in date9. format.
BRTHDT
23FEB1998
1973
Any tips on how to get my desired date field?
Thanks,
Kumar
If the output should be 23FEB1998 in one case and 1973 in another case, I think the best thing you can do is leave the variables as character.
If the output should be 23FEB1998 in one case and 01JAN1973 in another case, I think then you could easily read the results into a numeric variable.
data have;
dt='1988-02-23'; output;
dt='1973'; output;
run;
data want;
set have;
num_dt=input(cats(dt,'-01-01'),yymmdd10.);
format num_dt date9.;
run;
To create a SAS date value where the Date9 or any other date format will apply correctly, you need a day, month and year value. What day and month do you expect to have in the result when only a year , apparently, is supplied? Are the year only values always provided as 4 digits?
Do you have any other layouts for that character date value? We may need to see more to get code that works more completely.
This provides an example of how to read those two values into dates. You get to pick the month and day to use as the default for the MDY function that turns numeric month, day and year into a date. I used January 1 for the example.
data example; input BRTHDTC :$15.; if length(BRTHDTC)=4 then brthdt = mdy(1,1, input(BRTHDTC,4.)); else brthdt=input(BRTHDTC,yymmdd10.); format brthdt date9.; datalines; 1988-02-23 1973 ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.