BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

Hi,

 

Let's work with an Excel file with 5 columns (A-E) where the first row contains the variable name.

We want to set together the first data row (line 2) and the five and sixth row (line 6-7) using the libname excel engine and a set statement in a dataset.

It won't be possible because the range has to include the variable name and a syntax like this 'SASHELP_CLASS$A1:E1;A6:E7'n would not work.

 

Question: is it just not possible with libname engine+set statement or am I using the wrong syntax to define multiple ranges.

 

 

libname demo excel "&demo./reporting/class.xlsx";

data demo.'SASHELP CLASS'n;
    set sashelp.class;
run;

libname demo;

libname demo excel "&demo./reporting/class.xlsx";

data test;  
    set demo.'SASHELP_CLASS$A1:E2'n
        demo.'SASHELP_CLASS$A1:E1;A6:E7'n;
run;

libname demo;

proc print data=test noobs;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

If you write a "dataset" with a blank in its name, you have to use that again when referring to it:

libname demo xlsx "/folders/myfolders/class.xlsx";

data demo.'SASHELP CLASS'n;
set sashelp.class;
run;

data test;  
set
  demo.'SASHELP CLASS$A1:E2'n
  demo.'SASHELP CLASS$A1:E1;A6:E7'n
;

run;

proc print data=test noobs;
run;

This code worked in my SAS UE.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

If you write a "dataset" with a blank in its name, you have to use that again when referring to it:

libname demo xlsx "/folders/myfolders/class.xlsx";

data demo.'SASHELP CLASS'n;
set sashelp.class;
run;

data test;  
set
  demo.'SASHELP CLASS$A1:E2'n
  demo.'SASHELP CLASS$A1:E1;A6:E7'n
;

run;

proc print data=test noobs;
run;

This code worked in my SAS UE.

xxformat_com
Barite | Level 11

Thanks for the answer.

 

Actually, I was using the underscore because it was present in my Excel file because I was using a Excel engine, not a xlsx engine.

 

So basically the issue was not the syntax for the range

but the use of an Excel engine.

 

With excel engine, it does not work (not sure if it is a bug or just not implemented in the engine yet)

With xlsx engine, it works.

Kurt_Bremser
Super User

The EXCEL engine is Windows-only, and uses the ACE supplied by Microsoft; it is not available on UE (runs on Linux), therefore I used XLSX, which I recommend for future use anyway (you need to have files in the modern XLSX format, of course).

xxformat_com
Barite | Level 11

Hi,

If the selection is working fine for distinct rows, it does seem to work for distinct columns.

 

'SASHELP CLASS$A:C'n;  would select columns A, B and C which is ok.

'SASHELP CLASS$A:A;C:C'n; would also select columsn A, B and C instead of A and C.

 

libname demo xlsx "&demo./reporting/class.xlsx";

data test;  
   set demo.'SASHELP CLASS$A:A;C:C'n;
run;

libname demo;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1005 views
  • 1 like
  • 2 in conversation