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.;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.