BookmarkSubscribeRSS Feed
Michelle
Obsidian | Level 7

Hello, I am trying to create a sas dataset from a sybase database connection, and would like to figure out how to convert a date/time value to a SAS date value. The date is stored as smalldatetime in sybase. Right now, I have a proc sql followed by a data step that converts to SAS date. Does anyone know if there is way to do this within the proc sql? I am not familiar with sybase at all, and was hoping someone just happens to know how to do this... Thanks!

proc sql;

     connect to sybase as syb (user="&uid" password="&pwd" database="epi" server="db");

     create table test as

     select * from connection to syb

     ( set quoted_identifier off

          select date_entered,              /* would like to convert this to sas date without a data step */

               a, b, c

          from maintable

          where date_entered between "&dtbeg" and "&dtend"

     );

quit;

data test2;     /* would like to get rid of this data step */

set test;

dtent=datepart(date_entered);

drop date_entered;

run;

3 REPLIES 3
snoopy369
Barite | Level 11

Well, I don't know sybase, but you could do

proc sql;

     connect to sybase as syb (user="&uid" password="&pwd" database="epi" server="db");

     create table test as

     select a,b,c,datepart(date_entered) as date_entered from connection to syb

     ( set quoted_identifier off

          select date_entered,                              /* would like to convert this to sas date without a data step */

          from maintable

          where date_entered between "&dtbeg" and "&dtend"

     );

quit;

assuming a,b,c are the other columns you are interested in if there are any  (you have an extra comma that makes me think you do have some).

Michelle
Obsidian | Level 7

Yes I did have other variables of interest, and yes, that worked... To be honest, I have no clue why there are two select statements (I am working from inherited code) in the first place, and wasn't aware I could specify variables in the first one as well as the 2nd one.

snoopy369
Barite | Level 11

Technically, the lower down select is something executed in SYBASE, while the earlier select is a SAS statement that is selecting from the cursor or whatever it's called returned from SYBASE.  Most commonly passthrough is used by people who are more comfortable (or at least, are very comfortable) in the passthrough language (ie, SYBASE in this case) and are happy to do all the work in the passthrough language (hence the select *) - but there's no rule that you have to.  You can do WHERE statements and such as well in that outer query.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2315 views
  • 2 likes
  • 2 in conversation