Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting Date value from SAS

Status
Not open for further replies.

jmgrin

MIS
Jan 4, 2002
32
US
I am trying to export data from a SAS dataset to an Access database and I'm having trouble getting the date to export correctly. The date that's getting to my Access table is 1/1/1960 which I know is SAS's starting point for storing dates. Here is the test code I've been using. What am I doing wrong?


libname JobLib odbc dsn=JobStats;
DATA CUSTOMER;
INPUT @1 CUSTOMER 3.
@5 JobNum $3.
@17 reccnt 5.
@23 ProcCnt 2.
@26 jobtype $5.;

procdate=today();
format procdate date8.;
cards;
123 780 00045 01 EVAL
456 790 00135 01 EVAL
;
proc sql;
insert into joblib.jobstat(customernumber, jobnumber,processdate, recordcount, processingcount, jobtype)
(select customer, jobnum,datepart(procdate), reccnt, proccnt, jobtype from customer);
quit;
run;


















































































































































































































































































































 
jmgrin,
Access stores dates in seconds from a 1/1/1970. SAS stores date values as the number of days from 1/1/1960. What you need to do is use SAS DATETIME vars.
(ex.
date_var = datetime(); *** todays date in seconds;
I believe that with SAS/ACCESS or SAS/ODBC engines the difference (in seconds) are taken care of.

I hope that this helps you.
Klaz
 
Thanks for your response.
If I understand what you're saying, in my sample code, I should replace procdate=today with procdate=datetime().

If that's what you meant, it still is giving me a date of 1/1/1960 in my access table. Any other thoughts?
 
I took out the format statement ...
Same result -- 1/1/1960 in my access database.
 
Have you also taken out the Datepart() function from your SQL statement?
 
Yes, I've also tried removing the Datepart(). I keep thinking I'm missing something very simple. This should not be this difficult. Thanks.
 
Ignore my last response. I tried it again without the datepart and it worked fine. Thanks for your help.

So this is what worked:

libname JobLib odbc dsn=JobStats;
DATA CUSTOMER;
INPUT @1 CUSTOMER 3.
@5 JobNum $3.
@17 reccnt 5.
@23 ProcCnt 2.
@26 jobtype $5.;

procdate=datetime();
cards;
123 780 00045 01 EVAL
456 790 00135 01 EVAL
;
proc sql;
insert into joblib.jobstat(customernumber, jobnumber,processdate, recordcount, processingcount, jobtype)
(select customer, jobnum,procdate, reccnt, proccnt, jobtype from customer);
quit;
run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top