- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
Can any one help me with Extracting only date part from datetime with full program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Does not the above solution to the problem meet your needs? If not explain in detail.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
Important point: if something does not work, we don't know what you did. You need to show us your code, if there are errors in the log, show us the entire log for this DATA step; if it works but gives an answer you think is wrong, show us your code and show the wrong answer.
Wild guess:
You did not assign a format to the variable created by datepart(date), and it returns an answer of zero, which is the correct answer. You need to assign a DATE9. format to this variable to show the dates in "human readable" form which is 01JAN1960.
If that's not it, provide the information I asked for.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Jeetesh PeterClemmensen has given the full program which is extracting only date part.
I am copy pasting his programme below and I will share what each step means.
data want;
/*Here you are creating the dataset which you want to create*/
set original;
/*Here you are reading the data which has this date variable*/
date1 = datepart(date);
/*Here you are extracting date part of the date in a variable named date1*/
format date1 date9.;
/*However, it will be sas date value, so to bring it in human readable form this date9 format it used*/
run;
Feel free to let us know if anything of this is not understood.
Thank you.
- Dr. Abhijeet Safai
Certified Base and Clinical SAS Programmer
Associate Data Analyst
Actu-Real