Good afternoon,
I have data set, the date is Char, I need convert to Date.
data Set: Test_date
DOB DOB2
19380527 1938-05-27
19720416 1972-04-16
19400701 1940-07-01
19520821 1952-08-21
19451202 1945-12-02
19320128 1932-01-28
19410922 1941-09-22
19620520 1962-05-20
19310303 1931-03-03
19300816 1930-08-16
My SAS program, but do not know this is not working:
data new ;
set test_date;
b = (SUBSTR(DOB,1,4)||'-'||SUBSTR(DOB,5,2)||'-'||SUBSTR(DOB,7,2));
c=input(dob2,mmddyy10.);
format c mmddyy10.;
d=datepart(c);
run;
Please help/ I need convert DOB2 from Char to Date format.
data have;
input DOB :$10. DOB2 :$10. ;
cards;
19380527 1938-05-27
19720416 1972-04-16
19400701 1940-07-01
19520821 1952-08-21
19451202 1945-12-02
19320128 1932-01-28
19410922 1941-09-22
19620520 1962-05-20
19310303 1931-03-03
19300816 1930-08-16
;
data want;
set have;
num_dob=input(dob,yymmdd10.);
num_dob2=input(dob2,yymmdd10.);
format num_dob: date9.;
run;
data have;
input DOB :$10. DOB2 :$10. ;
cards;
19380527 1938-05-27
19720416 1972-04-16
19400701 1940-07-01
19520821 1952-08-21
19451202 1945-12-02
19320128 1932-01-28
19410922 1941-09-22
19620520 1962-05-20
19310303 1931-03-03
19300816 1930-08-16
;
data want;
set have;
num_dob=input(dob,yymmdd10.);
num_dob2=input(dob2,yymmdd10.);
format num_dob: date9.;
run;
You can read that character value with the yymmdd8. or yymmdd10 informat depending on which one. Your code shows DOB but you ask about DOB2 so I am not sure what you actually want.
But consider;
data example; input dob yymmdd8.; format dob mmddyy10.; datalines; 19380527 19720416 19400701 19520821 19451202 19320128 19410922 19620520 19310303 19300816 run;
Thank you.
Thank you. this works.
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.