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.;
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.