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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.