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

I am a new SAS user.  I imported a date in the format dd-mmm-yy that was unfortunately read as a character variable ($9).  I need to convert it to a date so that I can perform logical operations on it.  How do I convert this variable to a date variable?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
data example;
   x='11-FEB-16';
   date = input(compress(x,'-'),date7.);
   put date mmddyy10.;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User
data example;
   x='11-FEB-16';
   date = input(compress(x,'-'),date7.);
   put date mmddyy10.;
run;
RandiRyterman
Fluorite | Level 6

Thanks so much!!!

Cynthia_sas
SAS Super FREQ

Hi:

  Here's an example I use with my students. CHARDAY is a character string and BIRTHDAY is created as the number of days from Jan 1, 1960 by using the INPUT function.

cynthia

data bday;
  length charday $9;
  infile datalines;
  input name $ charday $;
return;
datalines;
alan 01jan1960
barb 15nov1950
carl 29nov1984
dana 29sep2014
;
run;
  
data howold;
  set bday;
  birthday = input(charday,date9.);
  howold_days = (today()-birthday);
  howold_years = (today()-birthday)/365.25;
run;
  
title "After converting CHARDAY to numeric BIRTHDAY";
proc print data=howold;
  var name charday birthday howold_days howold_years;
  format birthday mmddyy10.;
run;
RandiRyterman
Fluorite | Level 6

Thank you for this example!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 4 replies
  • 21636 views
  • 1 like
  • 3 in conversation