BookmarkSubscribeRSS Feed
x2008kyr
Calcite | Level 5

Hi there, I am trying to automate a report by exporting data into an excel template with multiple sheets (one for each month) and a number of different already defined named ranges. I am having trouble referencing the named range on a specific sheet when trying to output the data to it. I get the following error...

 

ERROR: Error attempting to CREATE a DBMS table. ERROR: Execute: 'April$APR_date' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

 

I assume I am getting the error because of the '$' used to specify which sheet I am referring to... SAS CODE:

 

*create date generated;
data date;
	v1="AS OF:";
	date=today()-1;
	format date date9.;
run;

*import template;
libname R1600f excel "Z:\Information Analysis & Distribution\Performance Management\Reporting\Renal\Phase 2 Reporting\R1600 - Dialysis Treatments\WORKING\R1600 - MONTHLY2.xlsx";

*delete named ranges;
proc datasets library=R1600f  nolist;
	delete 'April$APR_date'n;
run;

data R1600f.'April$APR_date'n;
	set date;
run;

*disconnect from template;
libname R1600f clear;

 

 

I have verified that the named range in SAS is April$APR_date which corresponds to the range name APR_date on the April worksheet.

 

Any help would be greatly appreciated.

2 REPLIES 2
Reeza
Super User

Start by checking what SAS is seeing, I would swithc Excel to XLSX as well. 

 

libname R1600f xlsx "Z:\Information Analysis & Distribution\Performance Management\Reporting\Renal\Phase 2 Reporting\R1600 - Dialysis Treatments\WORKING\R1600 - MONTHLY2.xlsx";

proc datasets lib=R1600f;
run;

This should tell you all the names in the files. 

If you absolutely cannot get this working, I recommend switching to PCFILES instead.

 

libname R1600f pcfiles path ="Z:\Information Analysis & Distribution\Performance Management\Reporting\Renal\Phase 2 Reporting\R1600 - Dialysis Treatments\WORKING\R1600 - MONTHLY2.xlsx";

Run the same thing as above, find the data set name, drop it and then reexport your data. I've done this using PCFILES many a time, so 99% sure that should work fine. I've had issues with XLSX 

 


@x2008kyr wrote:

Hi there, I am trying to automate a report by exporting data into an excel template with multiple sheets (one for each month) and a number of different already defined named ranges. I am having trouble referencing the named range on a specific sheet when trying to output the data to it. I get the following error...

 

ERROR: Error attempting to CREATE a DBMS table. ERROR: Execute: 'April$APR_date' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

 

I assume I am getting the error because of the '$' used to specify which sheet I am referring to... SAS CODE:

 

*create date generated;
data date;
	v1="AS OF:";
	date=today()-1;
	format date date9.;
run;

*import template;
libname R1600f excel "Z:\Information Analysis & Distribution\Performance Management\Reporting\Renal\Phase 2 Reporting\R1600 - Dialysis Treatments\WORKING\R1600 - MONTHLY2.xlsx";

*delete named ranges;
proc datasets library=R1600f  nolist;
	delete 'April$APR_date'n;
run;

data R1600f.'April$APR_date'n;
	set date;
run;

*disconnect from template;
libname R1600f clear;

 

 

I have verified that the named range in SAS is April$APR_date which corresponds to the range name APR_date on the April worksheet.

 

Any help would be greatly appreciated.


 

x2008kyr
Calcite | Level 5

Hi Reeza,

 

Thank you for the prompt reply.

 

I realized what my issue was. I didn't realize that when the named ranges were created that they someone defaulted to a scope that was worksheet specific and not the global scope "workbook". Apparently SAS will only recognize named ranges that are defined with a global scope in excel.

 

Jessy

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1584 views
  • 3 likes
  • 2 in conversation