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

I have a cross-sectional dataset with one observation of a integer variable for each individual. Individuals belong to 3 groups. I want to get the frequency distribution of the integer variable across individuals separately for each group and export the results to one Excel file (called FILENAME) with one sheet for each group. I use ODS EXCEL .

Results for the first group export without issues, but the second group produces the following error:

"A component of PATHNAME\FILENAME.xlsx is not a directory. ERROR: No body file. EXCEL output will not be created." where PATHNAME is the path for the folder where I want to save the Excel file.

 

Here is a simple example with a SAS Help dataset: 

data test;
set 	sashelp.Class;
run;

*Female;
ods excel file="PATHNAME\test.xlsx" 
	options(sheet_name="Female" 
			embedded_titles="yes"
			embed_titles_once="yes");


proc freq data = test(where=(sex="F"));
	label Age='Age at survey';
	tables age;
	title "Age at survey for female participants";
run;


*Male;
ods excel file="PATHNAME\test.xlsx" 
	options(sheet_name="Male" 
			embedded_titles="yes"
			embed_titles_once="yes");


proc freq data = test(where=(sex="M"));
	label Age='Age at survey';
	tables age;
	title "Age at survey for male participants";
run;

ods excel close;	

The sheet for female individuals exports without issues, but the sheet for male individuals generates the following error right after the ODS EXCEL statement and before the PROC FREQ statement:


ERROR: A component of PATHNAME\test.xlsx is not a directory.
ERROR: No body file. EXCEL output will not be created.
NOTE: Writing EXCEL file: S:\Projects\COVID19_ESPI\Community Cohort\3_Output\Non_response\test.xlsx

 

How can I solve this issue? 

I saw that for exporting html files defining the path and file separately can work. However, ods excel does not seem to support that option. 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
CurtisMackWSIPP
Lapis Lazuli | Level 10

You only need to give the file name once.  Just delete 

file="PATHNAME\test.xlsx" 

 from the second ODS call.

View solution in original post

4 REPLIES 4
CurtisMackWSIPP
Lapis Lazuli | Level 10

You only need to give the file name once.  Just delete 

file="PATHNAME\test.xlsx" 

 from the second ODS call.

Zoe8SAS
Fluorite | Level 6
Thank you! This works. This was clearly a Stata user error.
RichardDeVen
Barite | Level 11
  • Specify the filename and initial option settings in the first ODS EXCEL FILE=... OPTIONS(...) statement
  • Change active option settings with an ODS EXCEL OPTIONS(...) statement

 

Example coding template

ods EXCEL
  file="PATHNAME\test.xlsx" 
  options(embedded_titles="yes" embed_titles_once="yes")
;

ods EXCEL options(sheet_name="Female");
...
run;

ods EXCEL options(sheet_name="Male");
...
run;

ods EXCEL close;

I would agree the is not a directory ERROR is quite obtuse and could be better stated as "ERROR: The ODS EXCEL destination is already open"

 

NOTE: You can have multiple destinations open at once if your name your destinations.

 

Example:

ODS EXCEL(boss) file="...boss.xlsx";
ODS EXCEL(qa) file="...qa.xlsx";
ODS HTML file="...general.html";

... code block 1 ...
ODS EXCEL(boss) CLOSE;
... code block 2 ...
ODS HTML CLOSE;
... code block 3 ...
ODS EXCEL(qa) CLOSE;

 

Zoe8SAS
Fluorite | Level 6
Thanks for this detailed response! This works.

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
  • 4 replies
  • 3038 views
  • 3 likes
  • 3 in conversation