Sorry, its really hard to follow that. Just put some error checking code around the block in question:
%macro do_report (parm=); %if ¶m. ne %then %do; ... report set %end; %else %do; ... report blank set %end;
...
I used following code:
data _null_;
rc = stpsrv_header('Content-disposition','attachment; filename=test.xls');
rc = stpsrv_header('Content-disposition',"inline");
run;
PROC SQL NOPRINT;
SELECT COUNT(*) INTO: TOTALOBS
FROM HISTORY_DATA_TAB1;
QUIT;
%macro norecord;
/*%if &TOTALOBS eq 0 %then %do; */
data norecord1;
x= " NO RECORD FOUND FOR THIS CONTRACT ";
run;
TITLE "Basic Information Report";
PROC REPORT DATA= norecord1 MISSING;
COLUMN x
;
DEFINE X / DISPLAY "NO RECORD FOUND" FORMAT=$CHAR40. STYLE(column)={cellwidth=2.2in};
RUN;
/*%end; */
%mend;
%MACRO ALLRECORD1;
TITLE "Basic Information Report";
PROC REPORT DATA=HISTORY_DATA_TAB1 MISSING;
COLUMNS
COMPANY_CODE
CONTRACT_NUMBER
ISSUE_DATE
;
DEFINE COMPANY_CODE / DISPLAY "COMPANY CODE" FORMAT=$CHAR3.;
DEFINE CONTRACT_NUMBER / DISPLAY "CONTRACT NUMBER" FORMAT=$CHAR10.;
DEFINE ISSUE_DATE / DISPLAY "ISSUE DATE" FORMAT=$CHAR8.;
RUN;
%MEND;
%MACRO ALL1;
%IF &TOTALOBS NE 0 %THEN %DO;
%ALLRECORD1;
%END;
%ELSE %DO;
%norecord;
%END;
%MEND;
%ALL1;
Here the point to note is that when HISTORY_DATA_TAB1 dataset has record , it run successfully and give output to excel without any error, while HISTORY_DATA_TAB1 dataset does not have any record it is throwing error while opening excel file saying that excel is corrupted.
This logic is working fine in all other reports i have created.
Can i get some help on this ?
You have two Content-disposition headers and it is unclear which one the browser honors. You need only one.
Which ODS destination are you using?
Are you using STPBEGIN and STPEND?
What is the exact error that you get from Excel?
Are there any errors, warnings, or messages in the SAS log?
Can you save and then post a copy of the file that gives the error.
Here is a common error that you encounter when the file extension does not match the file content:
Error opening file: "The file format differs from the format that the file name extension specifies"
Vince DelGobbo
SAS R&D
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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: