BookmarkSubscribeRSS Feed
AAdams
Calcite | Level 5
Hello,
I am importing a date from Access 2002-2003 into SAS 9. The date gets imported into SAS as:
ddmmmyyyy:hh:mm:ss

Even though it is in datetime19, SAS won't read it. I looked up in the documentation and found information on sasdatefmt, but I'm clearly not using it right.

Here are some of my attempts:

data FluShot2007; /*Previously imported from Access & sorted*/
format Date datetime19.;
set work.dateinfo (sasdatefmt = (Date = 'Datetime19.'));

data flu2007;
merge Patients0708 (keep = PatientID Gender) FluShot2007;
by PatientID;

FluShot = 0;
If VaccineType = 'Flu' then FluShot = 1;

Year = year(Date);
run;

2nd Attempt:

data flu2007;
merge Patients0708 (keep = PatientID Gender) FluShot2007;
by PatientID;

format Date datetime19.;
set work.dateinfo (sasdatefmt = (Date = 'Datetime19.'));
FluShot = 0;
If VaccineType = 'Flu' then FluShot = 1;

Year = year(Date);
run;

3rd attempt:

data flu2007;
merge Patients0708 (keep = PatientID Gender) FluShot2007;
by PatientID;

format Date datetime19.;

FluShot = 0;
If VaccineType = 'Flu' then FluShot = 1;

Year = year(Date);
run;

Can someone help tell me what I am doing wrong? Thanks!
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
It looks to me like you have read the documentation:
http://support.sas.com/documentation/cdl/en/acpcref/61891/HTML/default/a003079774.htm
http://support.sas.com/documentation/cdl/en/acreldb/63023/HTML/default/a001371624.htm
http://support.sas.com/kb/6/413.html

However, my interpretation of the notes is that you use the SASDATEFMT option either in your config file or on your LIBNAME or SET statement when you are using SAS/ACCESS or the various engines to initially READ the data from Oracle or DB2 or Microsoft Access into a SAS data set.

Once your data are in SAS data format, then I believe that the SASDATEFMT option will no longer impact the data. You would then need to use other SAS formats, functions or conversion methods to impact the date or create a new variable.

You might investigate using the DATEPART function or the TIMEPART function to create new variables, as shown in the code below.

cynthia
[pre]
data testdate;
bday_time = '15Nov1950:07:15:35'dt;
try1 = year(bday_time);
try2 = year(datepart(bday_time));
month = month(datepart(bday_time));
bday = day(datepart(bday_time));
timeval = timepart(bday_time);
run;

proc print data=testdate;
format bday_time datetime18. timeval time8.;
run;

[/pre]

Output from above program is:
[pre]
Obs bday_time try1 try2 month bday timeval

1 15NOV50:07:15:35 . 1950 11 15 7:15:35

[/pre]
AAdams
Calcite | Level 5
That worked perfectly. Thank you!

(Although, upon further inspection, I realized that all my data was from 2007, and I could have just said 'Year = 2007;' but hey, I've learned something new! And I import from Access all the time)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 2 replies
  • 740 views
  • 0 likes
  • 2 in conversation