BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sheller
Calcite | Level 5

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

4 REPLIES 4
Reeza
Super User

DATEPART() -> Extract date portion

PUT() -> Convert to string

ballardw
Super User

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.

 

 

Kurt_Bremser
Super User

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.);
pdhokriya
Pyrite | Level 9

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 82539 views
  • 3 likes
  • 5 in conversation