- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I currently have a table that has dates as a datetime fromat (example: 02FEB2015:00:00:00.000). I am trying to firgure out how I can convert this column into a string so it matches up with another table with there date fromat as 2015-02-01 (as a string). I know there is the CAT funtcion but I do not know how to only select parts of the DAte time format to create the date string.
I have tried converting it in a query builder with the following steps ( look at attchement for screenshots)
1.I put the datetime column in the select data field
2.select properties
3. change
4. selected the format that matched the other field.
once i did this the dates were no longer the same then what they were . The year was showin 1900 when all the years are 2015 etc.
What would be the best way to get it in sring fromat by YYYY-MM-DD?
then selected the datetime column and selected properies
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First, don't post example data or anything else in a Microsoft Office document. Nobody in his right mind opens such a file from the web, and the organizations that most people here work in have explicit provisions against it.
Post a screenshot image if necessary, but provide data in a textual format or even better in a data step that reads data from a cards; block.
To convert your SAS datetime value to the required string in a data step, use
newvar = put(datepart(oldvar),yymmddd10.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DATEPART() -> Extract date portion
PUT() -> Convert to string
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Working with DATES, DATETIMES and Times you need to know what is actually stored. DATES store numbers of Days, Datetimes numbers of seconds (both base with Jan 1, 1960 in SAS) and TIME is number of seconds since midnight.
When you say year looked like 1900 it makes me suspect that you were using Excel as that program uses a different base date (1 Jan 1900).
In either case changing the format does not change the underlying value. So a date expressed as a datetime will often be the base date or one day from it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First, don't post example data or anything else in a Microsoft Office document. Nobody in his right mind opens such a file from the web, and the organizations that most people here work in have explicit provisions against it.
Post a screenshot image if necessary, but provide data in a textual format or even better in a data step that reads data from a cards; block.
To convert your SAS datetime value to the required string in a data step, use
newvar = put(datepart(oldvar),yymmddd10.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Implemented the logic - num to char date
proc contents data = temp.dov out = con noprint;
run;
data con;
set con;
dp1 = datepart(crdate);
call symput ('date',put(dp1,date9.));
run;
%put &date;
data dov_1;
set dov_new;
by subject instancename;
if last.subject;
doe = "&date";
vd = put(datepart(visitdt),date9.);
day_diff = intck("day", vd, "&date");
if day_diff > 105;
drop visitdt;
run;
- Tags:
- pdhokriya@gmail.com