data want;
set original;
date1 = darepart(date);
run;
my date column looks like 01AUG18:18:47:42
and date1 column is changed into 21397 with numeric type.
how colud I extract date into 01AUG18 with date type?
data want;
set original;
date1 = datepart(date);
format date1 date9.;
run;
Add date9. format to your date1 variable. Remember, dates are just formatted numbers in SAS. A Date in SAS represents the number of days since 01Jan1960.
data want;
set original;
date1 = datepart(date);
format date1 date9.;
run;
Add date9. format to your date1 variable. Remember, dates are just formatted numbers in SAS. A Date in SAS represents the number of days since 01Jan1960.
Hi All,
Can any one help me with Extracting only date part from datetime with full program.
Does not the above solution to the problem meet your needs? If not explain in detail.
I have same problem. My date variable is 01JAN1960:01:47:52 (datetime20.). I tried datepart(date) and read day,month,year using substr, both not work, not sure why. Anybody has solution?
Thanks!
@lih wrote:
I have same problem. My date variable is 01JAN1960:01:47:52 (datetime20.). I tried datepart(date) and read day,month,year using substr, both not work, not sure why. Anybody has solution?
Thanks!
Run Proc Contents on your data set. Show us the result. Make sure do indicate which variable is the one in question.
If you don't know how to run proc contents it is very simple, place the name of your data set after the data= in the example code below:
proc contents data=yourdatasetname; run;
@lih wrote:
I have same problem. My date variable is 01JAN1960:01:47:52 (datetime20.). I tried datepart(date) and read day,month,year using substr, both not work, not sure why. Anybody has solution?
Thanks!
For the DATEPART() function to work the variable needs to NUMERIC with times since 1960 in seconds.
For the SUBSTR() function to work the value needs to be CHARACTER.
You cannot use them BOTH on the same variable.
If you have a variable named DATETIME that has DATETIME values then you can make DATE, YEAR, MONTH and DAY variables like this:
date=datepart(datetime);
year=year(date);
month=month(date);
day=day(month);
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.