I need help formatting a date as it's not something I have experience with. My variables startdate and enddate are coming in as 28Jan2000:00:00:00.000 is the data set I've been provided. How I go about making the dates just mmddyyyy and then keeping only those with a start date between 2006 and 2010?
Assuming your variable is numeric with a datetime format then you can:
data want;
set have;
*extracts date portion;
date_value = datepart(dateTime);
*format, primarily for display purposes;
format date_value mmddyy10.;
*filters;
if year(date_value) >= 2006 & year <=2010;
run;
@SAS_learneromg wrote:
I need help formatting a date as it's not something I have experience with. My variables startdate and enddate are coming in as 28Jan2000:00:00:00.000 is the data set I've been provided. How I go about making the dates just mmddyyyy and then keeping only those with a start date between 2006 and 2010?
If your datetime value is a character you will first need to convert it to a numeric datetime value:
dateTimeVar = input(charVariable, anydtdtm.);
format dateTimeVar datetime.;
Assuming your variable is numeric with a datetime format then you can:
data want;
set have;
*extracts date portion;
date_value = datepart(dateTime);
*format, primarily for display purposes;
format date_value mmddyy10.;
*filters;
if year(date_value) >= 2006 & year <=2010;
run;
@SAS_learneromg wrote:
I need help formatting a date as it's not something I have experience with. My variables startdate and enddate are coming in as 28Jan2000:00:00:00.000 is the data set I've been provided. How I go about making the dates just mmddyyyy and then keeping only those with a start date between 2006 and 2010?
If your datetime value is a character you will first need to convert it to a numeric datetime value:
dateTimeVar = input(charVariable, anydtdtm.);
format dateTimeVar datetime.;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.