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;
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).
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.