BookmarkSubscribeRSS Feed
gewing
Fluorite | Level 6

On SAS Grid, LIBNAME EXCEL doesn't work, so I'm stuck using LIBNAME XSLX.  There's one page on the SAS site that says that the XLSX engine has limited data set options as opposed to the EXCEL engine.  I've inherited a program that uses the data set options DBSASTYPE to set a group of variables later defined in array as numeric and DBSASLABEL=none.  I've tried using DBTYPE, and that also doesn't work.  The error is 'Invalid option'.  I can't find documentation ANYWHERE for the XLSX engine's available DATA step options, and I'd like to keep the program as close to the original, because it's quite elegant and is called by another program.

 

Does anyone have a workaround besides manually redoing everything?  I've considered swapping the code for PROC SQL, but not 100% sure how I'd incorporate the code below.  I don't want to do it variable by variable because I call this macro multiple times for sheets with different 'NEW_' variables.

 

libname edited XLSX "&file";

*Get names of new variables;
*Assuming new variables are named new_<oldvarname> in excel;
proc contents data=edited."&sheet."n out=varnames(keep=name) noprint; run;

data _null_;
length newvars oldvars $ 5000;
set varnames end=last;
retain newvars oldvars;

if upcase(scan(name,1,'_'))='NEW' then do;
oldvars=catx(' ',oldvars,scan(name,2,'_'));
newvars=catx(' ',newvars,name);
end;
if last then do;
call symput('NewVars',trim(newvars));
call symput('OldVars',trim(oldvars));
end;
run;

 

PROC SORT DATA=edited."&sheet."n(keep=id questid rostnumb new_: dbsaslabel=none  dbsastype=(id='CHAR(11)' questid='CHAR(7)' *These options don't work.;
%LET index = 1;
%LET newVar = %SCAN(&newVars., &index.);
%DO %WHILE ("&newVar." ~= "");
&newVar.='NUMERIC'
%LET index = %EVAL(&index. + 1);
%LET newVar = %SCAN(&newVars., &index.);
%END;
))
out=chgs; BY &sort.;
RUN;

2 REPLIES 2
dgritt
Obsidian | Level 7

Can you provide an example spreadsheet?

ChrisNZ
Tourmaline | Level 20

Not too sure about the libname, but for sql you could do:

proc sql;

   create table CHGS as

   select ID length=11  label=' ', QUESTID length=7 label=' '

%LET index = 1;
%LET newVar = %SCAN(&newVars., &index.);
%DO %WHILE ("&newVar." ~= "");
  ,&newVar.  label=' '
%LET index = %EVAL(&index. + 1);
%LET newVar = %SCAN(&newVars., &index.);
%END;

from edited."&sheet."n
order by &sort;

quit;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1139 views
  • 1 like
  • 3 in conversation