BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

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;
ballardw
Super User

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;
JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

Thank you.

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

Thank you. this works.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 743 views
  • 0 likes
  • 3 in conversation