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.
Please post few lines with relevant varaibles only from the excel and explain, better by wanted output, what do you want.
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 ?
Assign excel cells format to display dates, then close and save the excel with its new format.
Import the excel only when closed.
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.
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
Specifcally looking at the dates column, you will find that some of the output is in serial number format and some show actual dates.
Maybe you just need add sas format to the date:
format date date9. ; /* or ddmmyy10. or mmddyy10. or any other available date format */
Alright, what is the procedure to adjust dates within excel spread sheets in sas
do I type an informat line before typing a format ?
What is your code to import the excel ?
My Code-
proc import datafile="C:\Users\okund\Desktop\Practicum Documents\2016MosqDataEntry.xlsx"
out=Grad.mosdata
dbms=xlsx replace;
getnames=yes;
run;
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;
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 ?
Also why is SAS reading Date as a character variable ?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: