BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Geo-
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Super User
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. 

 

 

View solution in original post

6 REPLIES 6
PeterClemmensen
Super User
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. 

 

 

Jeetesh
Calcite | Level 5

Hi All,

 

Can any one help me with Extracting only date part from datetime with full program.

PaigeMiller
Diamond | Level 26

Does not the above solution to the problem meet your needs? If not explain in detail.

--
Paige Miller
lih
Calcite | Level 5 lih
Calcite | Level 5

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!

ballardw
Super User

@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;
Tom
Super User Tom
Super User

@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);

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 70626 views
  • 3 likes
  • 7 in conversation