DATA Step, Macro, Functions and more

convert a string to a date value

Accepted Solution Solved
Reply
Super Contributor
Posts: 286
Accepted Solution

convert a string to a date value

sample data for dob:

12201999

01142000

10091998

Code I tried:

dobm=substr(dob,1,2);
dobd=substr(dob,3,2);
doby=substr(dob,5,4);
dobchar=compress(dobm||'/'||dobd||'/'||doby);
dobnum=input(strip(dobchar),mmddyy10.);
run;

ERROR:

NOTE: Invalid argument to function INPUT at line 622 column 8.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.


Accepted Solutions
Solution
‎09-22-2017 03:29 PM
Super User
Posts: 6,774

Re: convert a string to a date value

It's not clear whether your original DOB variable is numeric or character.

 

If it's character:

 

dobnum = input(dob, mmddyy8.);

format dobnum yymmdd10.;    /* or whatever format you prefer */

 

If it's numeric:

 

dobunum = input( put(dob,z8.), mmddyy8.);

format dobnum yymmdd10.;   /* or whatever format you prefer */

View solution in original post


All Replies
Solution
‎09-22-2017 03:29 PM
Super User
Posts: 6,774

Re: convert a string to a date value

It's not clear whether your original DOB variable is numeric or character.

 

If it's character:

 

dobnum = input(dob, mmddyy8.);

format dobnum yymmdd10.;    /* or whatever format you prefer */

 

If it's numeric:

 

dobunum = input( put(dob,z8.), mmddyy8.);

format dobnum yymmdd10.;   /* or whatever format you prefer */

Trusted Advisor
Posts: 1,837

Re: convert a string to a date value

Posted in reply to Astounding

@Astounding, dob is a string according to the subject and to the use of substr.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 118 views
  • 0 likes
  • 3 in conversation