Above errors are from running this:
filename mail email
FROM=( ".com" )
TO=( ".com" )
CC=( )
TYPE='TEXT/HTML'
SUBJECT="SUBJECT &repdate"
LRECL=32767
%if (&num_recs >0) %then %do;
ATTACH=("FILEPATH_&repdate..xlsx"
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
end;
Closer, but still a NO. It's telling me the %IF and %END statements aren't valid in open code. It's also STILL sending an empty Excel file.
filename mail email
FROM=( "" )
TO=( "" )
CC=( / )
TYPE='TEXT/HTML'
SUBJECT="SUBJECT for &repdate"
LRECL=32767
%if (&num_recs >0) %then %do;
ATTACH=("FILEPATH_&repdate..xlsx"
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
%end;
;
This means that you have an older SAS version where the "open code" %IF was not possible.
You need to wrap your code into a macro definition and call the macro:
filename mail email
FROM=( ".com" )
TO=( ".com" )
CC=( )
TYPE='TEXT/HTML'
SUBJECT="SUBJECT &repdate"
LRECL=32767
%macro cond_attach;
%if (&num_recs >0) %then %do;
ATTACH=("FILEPATH_&repdate..xlsx"
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
%end;
%mend cond_attach;
%cond_attach /* no semicolon here! */
@hnb_matt_d wrote:
ERROR: The %IF statement is not valid in open code. ERROR: Error in the FILENAME statement. ERROR 23-2: Invalid option name end. ERROR: Insufficient authorization to access /var/spool/mail/srvsasadm.
You have a number of options to fix this.
filename email
....
%sysfunc(ifc(&num_recs >0,ATTACH=("FILEPATH_&repdate..xlsx" content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),))
...
;
%let attach=;
data _null_;
set my_data ;
call symputx('attach'
,'ATTACH=("FILEPATH_&repdate..xlsx" content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")'
);
stop;
run;
...
filename email
....
&attach
...
;
I leave it as an exercise for you to figure out which you want to use and how to update your code to use. Make sure that the code you create is valid SAS code and it is still valid SAS code once the conditional part is generated.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.