Help using Base SAS procedures

Importing Excel with 24 sheets

Reply
Regular Contributor
Posts: 229

Importing Excel with 24 sheets

Hi

i have a Excel in this i have 24 sheets sheet1 to sheet24 all this sheets have same variables how can i import all the sheets at once.
Valued Guide
Posts: 2,175

Re: Importing Excel with 24 sheets

use sas libname engine for excel, like[pre] libname ex 'your.work.book.xls' ;[/pre]Unfortunately, to copy all sheets into the work library:[pre] proc copy in= ex out= work ;
run ; [/pre]didn't work for me. Not even with [pre]option validvarname= ANY ;[/pre]However, this copies sheet1[pre]data s1; set ex."sheet1$"n ; run;[/pre]So, you could use a macro loop, or more simple CALL EXECUTE(), like[pre] data _null_ ;
do ns= 1 to 24 /*yoursheet count*/ ;
ds = 'S' !! put( ns, 2.-L );
sh = 'sheet' !! put( ns, 2.-L );
call execute( 'data ' !! ds ) ;
call execute( '; set ex."' !! trim(sh)!! '$"n ; run; ' ) ;
end;
run;[/pre]...... it works for me.
Then you can work with the 24 data sets in the work library named S1 to S24.

good luck

PeterC
Super Contributor
Posts: 273

Re: Importing Excel with 24 sheets

a little addon is neccessary in case your nine first sheet names are
written as sheet01-sheet09 in place of sheet1-sheet-9 sheet10-sheet24

Change this line in forwarded code
sh = 'sheet' !! put( ns, z2.-L );

Andre
Ask a Question
Discussion stats
  • 2 replies
  • 123 views
  • 0 likes
  • 3 in conversation