Hi all,
I have a set of XLS (not a typo) files that need to be read in to SAS.
I'm using libname Excel, which is working pretty well except for one thing:
I want every one of the 150+ variables to be read in as character, but SAS is deciding basically all of them are numeric (I don't know if that's because the first few rows are missing? But it is).
I tried adding an attrib statement when reading in the files, but this just causes a bunch of warnings that each var is being defined as both char and numeric.
This is the relevant code snippet, which cycles through a file list (&list_of_files), grabs each sheet name, and reads in the file using the attrib statement:
Are all of these "hundreds" of XLS supposed to be of the same structure?
If they are of the same structure it may be worth writing a data step that takes, a hopefully known, sheet name and does the conversion manually. Which for numeric to character is going to mean multiple: Newvarname = put(numericvarname, someformatname. -L) statements. The Attrib would go to the new variables with different names. And drop the old ones.
Or do the rename shuffle as in this thread: https://communities.sas.com/t5/SAS-Programming/Why-I-couldn-t-change-categories-of-some-of-my-charac...
Make sure to set the length of the resulting variables so you know what they are when you go to use these.
PS: You do not want DATES, TIMES or DATETIME values as character. Almost any use of those would require a first step of getting a numeric date, time or datetime value. So don't cause yourself more work.
Does each XLS file contain multiple sheets?
One trick that usually forces the variables to character is to tell it NOT to use the first row as the variable names.
Not sure about EXCEL engine but for normal PROC IMPORT code that is the GETNAMES=NO; statement.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.