Hi I am trying to write a code where I can get specific sheets named a1, b1, c1 from and excel file and append them and output them as a SAS file. this is the code I have been trying but I am getting the following error "ERROR: Couldn't find sheet in spreadsheet". the code is as follows.
proc datasets lib=data nolist;
delete table_append;
quit;
run;
%let varlist1= a1~b1~c1;
%macro testing2();
%do i1 = 1 %to %sysfunc(countw("&vallist1", "~"));
%let kk1 = %scan(&vallist1, &i1,~);
PROC IMPORT
OUT= testex
DATAFILE= "C:\location\cases.xlsx"
DBMS=xlsx
REPLACE;
SHEET="&kk1";
GETNAMES=YES;
RUN;
data aan1;
set testex;
run;
proc append base=data.table_append data= aan1 Force;
run;
%end;
%mend testing2;
%testing2;
Since the macro language knows only text as data type, no quotes are needed:
%do i1 = 1 %to %sysfunc(countw(&vallist1,~));
But I suspect your process will not be stable because of the vagaries of PROC IMPORT. You will be much better off saving the sheets to text files so you can read them all in one single data step.
%let varlist1= a1~b1~c1;
%macro testing2();
%do i1=1 %to %sysfunc(countw(&varlist1, ~));
%let sheetName = %scan(&varlist1, &i1, ~);
%put &sheetname;
PROC IMPORT OUT=testex DATAFILE="C:\location\cases.xlsx" DBMS=xlsx REPLACE;
SHEET="&sheetName";
GETNAMES=YES;
RUN;
proc append base=data.table_append data=testex Force;
run;
*delete table otherwise if proc import fails it will reload old data;
proc sql;
drop table testex;
quit;
%end;
%mend testing2;
%testing2;
@eroolpal wrote:
Hi I am trying to write a code where I can get specific sheets named a1, b1, c1 from and excel file and append them and output them as a SAS file. this is the code I have been trying but I am getting the following error "ERROR: Couldn't find sheet in spreadsheet". the code is as follows.
proc datasets lib=data nolist;
delete table_append;
quit;
run;
%let varlist1= a1~b1~c1;%macro testing2();
%do i1 = 1 %to %sysfunc(countw("&vallist1", "~"));
%let kk1 = %scan(&vallist1, &i1,~);
PROC IMPORT
OUT= testex
DATAFILE= "C:\location\cases.xlsx"
DBMS=xlsx
REPLACE;
SHEET="&kk1";
GETNAMES=YES;
RUN;
data aan1;
set testex;
run;
proc append base=data.table_append data= aan1 Force;
run;%end;
%mend testing2;
%testing2;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: