02-09-2018 02:00 PM
I want to import all the sheets in an excel file with the following conditions:
1) import all sheets without having to specify sheet names (there are too many)
2) import row 6 as the heading (column name) and delete rows 1-5 for each sheet. Each sheet has the same column names.
3) Preferably wan to append each sheet to get 1 dataset. Again, each sheet as the same column names starting on row 6.
Anyone have any tips to code this import?
02-09-2018 02:09 PM
1. Assign a libname and get all the sheet names from the libname and proc datasets
2. You can import them all using PROC COPY and then use a macro to process the data sets.
3. You'll get mixed types when you import all of the data so you'll need to verify that first.
4. if they're all the same data layout then add a rename manually to make it easier on yourself. You can easily do this by taking the first row of the worksheet, transpose it in excel (copy/paste special) and then align the letters which is what SAS will call the data.
Then build a rename statement:
A = ID
B = Name
C = SSN
02-09-2018 02:13 PM
libname file XLSX 'C:\Users\.xlsx';
proc copy in=file out=WORK;
So when I do this it copies all of the comments in rows 1-5 and the columns names in row 6 as observations. I just dont want to go and manually deleted these rows for each sheet.
02-09-2018 02:18 PM
You can use the _N_ to process each sheet to delete the rows you don't need.
Ultimately you're going to have to do some processing.
The other option is to get the sheet names and then use a macro to import each sheet in turn using DATAROW to start at Row 7 but then you have to rename the variables.