Help using Base SAS procedures

converting sybase smalldatetime to SAS date value?

Reply
Contributor
Posts: 36

converting sybase smalldatetime to SAS date value?

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;

Regular Contributor
Posts: 244

Re: converting sybase smalldatetime to SAS date value?

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

Contributor
Posts: 36

Re: converting sybase smalldatetime to SAS date value?

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.

Regular Contributor
Posts: 244

Re: converting sybase smalldatetime to SAS date value?

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.

Ask a Question
Discussion stats
  • 3 replies
  • 621 views
  • 2 likes
  • 2 in conversation