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

I know this is going to sound so ridiculous, but bear with me, I'm fairly new to SAS and please in answer I am looking for example code. I have a dataset that I am preparing to do a linkage on. The date format is wrong for a variable it is a character defined variable with the numeric string formatted MMDDYYYY. I need to convert it to numeric so that this code below will work for converting the date. How do I convert the variable to numeric so I can use the code below? 

 

data set;
set set;
DOB=put(DOB,yymmdd8.);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your code is for creating a character variable from a date value.  So if your original variable is also character then you just add an INPUT() function call to convert it to a date so the PUT() function will work.

 

data WANT;
  set HAVE;
  DOB=put(input(DOB,mmddyy8.),yymmddN8.);
run;

Also if you want the result ot look like YYYYMMDD (with no delimiters) then use the yymmddN format.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Your code is for creating a character variable from a date value.  So if your original variable is also character then you just add an INPUT() function call to convert it to a date so the PUT() function will work.

 

data WANT;
  set HAVE;
  DOB=put(input(DOB,mmddyy8.),yymmddN8.);
run;

Also if you want the result ot look like YYYYMMDD (with no delimiters) then use the yymmddN format.

chadwae
Fluorite | Level 6

Thank you! I almost had it right, but was missing just a small part. This is perfect! 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 949 views
  • 1 like
  • 3 in conversation