BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello, I would like to convert a datetime and take the datepart in snowflake. The datepart(AUTHRSTN_DT) is not working.

How to do that?

 

 

AUTHRSTN_DT
05JUN2023:08:24:37.000000

Please note that AUTHRSTN_DT format is datetime25.6

authorisation_date=datepart(AUTHRSTN_DT);

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

If it's coming over as a legit datetime value into SAS it should work. However, if it's coming over as character then you'll have to convert it.

 

data g;
 AUTHRSTN_DT = '05JUN2023:08:24:37.000000';
 AUTHRSTN_DT_N = input(AUTHRSTN_DT ,datetime25.6);
 justDate = datepart(AUTHRSTN_DT_N );
 format justDate date9.;
run;

 

If using SAS/ACCESS to Snowflake libname, then you might need to use the DBSASTYPE option on the libname statement to ensure the column is treated as a SAS datetime.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

If it's coming over as a legit datetime value into SAS it should work. However, if it's coming over as character then you'll have to convert it.

 

data g;
 AUTHRSTN_DT = '05JUN2023:08:24:37.000000';
 AUTHRSTN_DT_N = input(AUTHRSTN_DT ,datetime25.6);
 justDate = datepart(AUTHRSTN_DT_N );
 format justDate date9.;
run;

 

If using SAS/ACCESS to Snowflake libname, then you might need to use the DBSASTYPE option on the libname statement to ensure the column is treated as a SAS datetime.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Patrick
Opal | Level 21

What's the value of &accountingDate?

 

What happens if you run below? Do you get any eodreport_date with a select_flg=0 that you would have wanted to select?

data test;
  set inforce_auto_cntrctver_org;
  if eodreport_date <= &accountingdate. then select_flg=1;
  else select_flg=0;
run;

proc freq data=test;
  table eodreport_date*select_flg /nocol norow nopercent;;
run;

 

AhmedAl_Attar
Rhodochrosite | Level 12

Hi @alepage 

if you are trying to pass this value over to Snowflake and use it there, then you may want to look at this SAS/ACCESS Interface to Snowflake

https://documentation.sas.com/doc/en/pgmsascdc/v_046/acreldb/n1d5j8d7wegfezn1irjj3hcrne1n.htm

 

Hope this helps

Patrick
Opal | Level 21

@alepage wrote:

Hello, I would like to convert a datetime and take the datepart in snowflake. The datepart(AUTHRSTN_DT) is not working.

How to do that?

To do what? To load a SAS table into Snowflake or to use it in a where clause to query Snowflake?

If query: If you run Proc Contents against the Snowflake table what type and format does the column show?

 

What's not working with datepart()? You get an error, or an undesired result, or the query just runs forever?

 

If it's for a query formulated in SAS SQL, the column in Snowflake is of type DateTime and you want all rows matching a specific date then below query should work and also get pushed to the DB for execution

where '05JUN2023:00:00:00'dt <= AUTHRSTN_DT < '06JUN2023:00:00:00'dt

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 1061 views
  • 1 like
  • 5 in conversation