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

Hello I need some help on this

 

I used this to see the time on this variable ADJDC_TM the variable has a data in there so I used

 

to_char(ADJDC_TM, 'YYYY-MM-DD HH:MI:SS AM') and I got  the correct result in SQL Developer

 

if I like to see the same result in SAS how do I that. What format I have to use. All the help appreciated.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

You can also use SQL pass-through in SAS and use the to_char() function if you want.

There are many papers on how to do this.

View solution in original post

19 REPLIES 19
novinosrin
Tourmaline | Level 20

something like 

put(ADJDC_TM, datetime20.);

for the datetime value?

 

Ahsan
Calcite | Level 5

I did try this and I am not getting right results meaning wrong data and time.

novinosrin
Tourmaline | Level 20

Have you explored and exhausted all datetime formats available in sas?

Reeza
Super User
Show an example of what you're starting off with and what you're trying to do please.
Ahsan
Calcite | Level 5

that's what I did in SQL developer I have attached the screen shot I wanna do same in SAS too.

Ahsan
Calcite | Level 5
SELECT t1.TRNSCT_CNTL_NBR,
to_char(ADJDC_TM, 'YYYY-MM-DD HH:MI:SS AM'),
t1.CLM_HDR_PD_DT,
t1.HDR_TYP_CD,
t1.HDR_STS_CD,
t1.ADJDC_DT,
t1.ADJDC_TM,
t1.CLM_HDR_INSRT_DT
FROM CLAIM_HEADER_CUR t1 WHERE t1.TRNSCT_CNTL_NBR IN
(
'abcdexusususu',
'abaskfkfdkfkfkfk',

ORDER BY t1.CLM_HDR_PD_DT;

I want to do same in SAS
Reeza
Super User
No screenshot. Please also include the recommended SAS code you said did not work.
ballardw
Super User

Incomplete code doesn't help.

 

A straight SAS Proc SQL would likely have thrown an error with

to_char(ADJDC_TM, 'YYYY-MM-DD HH:MI:SS AM'),

 

Show the SAS code you ran. Copy it from the LOG with all the messages involved and paste into a code box opened using the forum's {I} icon.

Tom
Super User Tom
Super User

I am pretty sure that even SQL_DEVELOPER cannot run emojis.  🙂 

Remember to use the Insert Code or Insert SAS Code icons to get a pop-up window to enter your example data/code.

 

Are you sure that your SAS variable has datetime values?  If you try to format a date value (number of days) as if it was a datetime value (number of seconds) you will get a value early in the year 1960.

Ahsan
Calcite | Level 5

ADJDC_TM.PNGSQL Developer ADJC_TM.PNG

 

Here is the screen shot of sql developer and SAS variable is not a datetime format. Here is the SAS code as well

PROC SQL;

CREATE TABLE WORK.QUERY_FOR_CLAIM_HEADER_CUR_0003 AS

SELECT t1.TRNSCT_CNTL_NBR,

 

t1.CLM_HDR_PD_DT,

t1.HDR_TYP_CD,

t1.HDR_STS_CD,

t1.ADJDC_DT,

t1.ADJDC_TM,

t1.CLM_HDR_INSRT_DT,

/* Test */

(PUT(ADJDC_TM, DATETIME20.)) AS Test

FROM WORK.QUERY_FOR_CLAIM_HEADER_CUR t1;

QUIT;

 

Reeza
Super User
PROC SQL;
CREATE TABLE WORK.QUERY_FOR_CLAIM_HEADER_CUR_0003 AS
SELECT t1.TRNSCT_CNTL_NBR,
 
t1.CLM_HDR_PD_DT,
t1.HDR_TYP_CD,
t1.HDR_STS_CD,
t1.ADJDC_DT,
t1.ADJDC_TM,
t1.CLM_HDR_INSRT_DT,
/* Test */
ADJDC_TM AS Test1,
ADJDC_TM AS Test2 format=datetime.,
ADJDC_TM AS Test3 format=date9.
FROM WORK.QUERY_FOR_CLAIM_HEADER_CUR t1;
QUIT;

You already have the data. What does this show up as?

 

I suspect one of the above is what you need. 

Ahsan
Calcite | Level 5

I used your method test2 give me the date and time but the date is wrong, Test3 give me the correct date but no time.

 

Capture.PNG

Tom
Super User Tom
Super User

@Ahsan wrote:

I used your method test2 give me the date and time but the date is wrong, Test3 give me the correct date but no time.

 

Capture.PNG


So you have proved that you have DATE values and not DATETIME values.  If try to format a date (number of days) as if it was a datetime (number of seconds) then it will look like a value in early 1960.

 

How did you create the SAS dataset?

Tom
Super User Tom
Super User

Your photograph is showing ADJDC_TM as just a date value.  But the TO_CHAR() function was able to find time values to add to the dates. 

 

If your values in SAS are only DATE values and not DATETIME values then the method you used to move the data has excluded the time part, just like what ever tool you used to make the report that you posted the photo of.

 

How did you move the data from that system into SAS? 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 19 replies
  • 1564 views
  • 0 likes
  • 6 in conversation