Hi,
I am bringing in a table from excel to SAS. I am having trouble with converting one of the columns into a character column. I have a column in excel with some of the cells as dates and some of the cells as text. I would like to import this column as text though. How can I do this?
Thanks.
It somewhat depends on how you're importing it (which DBMS you're using), but most of the time the MIXED=YES option is helpful for what you're asking. If not, post your full import code (with filename anonymized if needed) so you can get the best help possible.
PROC IMPORT OUT= WORK.IMPRT_EXCEL DATAFILE= 'C:/new.xls' DBMS=EXCELCS REPLACE; PORT=0000; SERVER='01.01.001.01'; SHEET="grp"; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN;
You said some date, some text.
What does that look like in Excel?
The column has dates like this 8/12/2012 and text like this "not signed". Some of the cells are blank too.
I could add three rows with text value at the top of your excel file to force sas treating your date column as text and delete the added row after importing.
You could also specify the value "guessingrows=32000". That will make SAS look at the first 32,000 rows of data to guess the type instead of the first 8.
If you can't be guaranteed that the text occurs in the first 32000 rows, then I would suggest not using proc import from an excel file (frankly I suggest this anyways. Excel is just an awful data storage program).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.