BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
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.
2 REPLIES 2
Peter_C
Rhodochrosite | Level 12
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
Andre
Obsidian | Level 7
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1094 views
  • 0 likes
  • 3 in conversation