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!
You only need to give the file name once. Just delete
file="PATHNAME\test.xlsx"
from the second ODS call.
You only need to give the file name once. Just delete
file="PATHNAME\test.xlsx"
from the second ODS call.
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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: