BookmarkSubscribeRSS Feed
Okundaye1
Calcite | Level 5

How do I convert serial Numbers within raw data into regular dates within SAS? I have an excel spreadsheet that has most of its dates as serial numbers rather than general dates. 

20 REPLIES 20
Shmuel
Garnet | Level 18

Please post few lines with relevant varaibles only from the excel and explain, better by wanted output, what do you want.

Okundaye1
Calcite | Level 5

Wanted Variable to be corrected Trap_Coll_Date;

Example:

---> 41503 is stored in excel, but it represents 8/17/2016 

 

Some dates are stored as serial numbers, some dates are stored as regular dates 

 

I can convert the serial numbers in excel into dates, but importing it to SAS reveals the original serial number from Excel. How to I fix this ? 

Shmuel
Garnet | Level 18

Assign excel cells format to display dates, then close and save the excel with its new format.

Import the excel only when closed.

ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Do you mean you are seeing values like 40123 in the spreadsheet that may represent 11/6/2009?

It may be as simple as setting the column to display as a date in Excel using the FORMAT Cells options.

 
Okundaye1
Calcite | Level 5

Yes it appears like that, I've tried using the format options to convert the serial numbers to dates.

The problem is not all the dates  were imputed into Excel as serial numbers. Some values appear as dates when formated options were changed from date to general. 

 

This is the SAS output after importing the excel file

Okundaye1
Calcite | Level 5

Specifcally looking at the dates column, you will find that some of the output is in serial number format and some show actual dates. 

Shmuel
Garnet | Level 18

Maybe you just need add sas format to the date:

   format date date9. ;  /* or ddmmyy10. or mmddyy10. or any other available date format */

Okundaye1
Calcite | Level 5

Alright, what is the procedure to adjust dates within excel spread sheets in sas 

do I type an informat line before typing a format ? 

Shmuel
Garnet | Level 18

What is your code to import the excel ?

Okundaye1
Calcite | Level 5

My Code- 

proc import datafile="C:\Users\okund\Desktop\Practicum Documents\2016MosqDataEntry.xlsx"
out=Grad.mosdata
dbms=xlsx replace;
getnames=yes;
run;

Shmuel
Garnet | Level 18

I'm not sure you can add the date format in PROC IMPORT.

So just add next code:

      proc import .....   /* your code as is */

         out=Grad.mosdata

          ...  

      run;

      proc datasets lib=grad nolist;

              modify mosdata;

              format date date9.;   /* or any other SAS date format */

     run; quit;

Shmuel
Garnet | Level 18
check the dates that are correct as in excel
Okundaye1
Calcite | Level 5

I used the code you sent me, and sas Log stated this: 

 

1320 proc datasets lib=grad nolist;
1321 modify mosdata;
ERROR: You are trying to use the numeric format DATE with the character variable trap_coll_date in
data set GRAD.MOSDATA.
1322 format Trap_Coll_Date date9.; /* or any other SAS date format */
1323 run; 

 

is this because sas is reading dates as a character variabel instead of a numberic variable ?

 

Okundaye1
Calcite | Level 5

Also why is SAS reading Date as a character variable ?

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
  • 20 replies
  • 2526 views
  • 2 likes
  • 4 in conversation