I have a dataset that has two variables. The first columns has string variable called savings and another column has dollar amount of savings. There are three types of savings. So, basically, there are three rows and two columns. I use this table to create an excel file using ODS tagset.
I do not want to create an excel file if there was no dollar amount in ALL three savings I second column.
Savings | Saving_Amount |
ABC | |
DEF | |
GHI |
How do I program this?
Thanks for your help.
Hi @SASMom2 You could use a conditional macro IF THEN statement
proc sql noprint;
select nmiss(Saving_Amount) ne count(*) into :check trimmed
from have;
quit;
%put &=check;
%if &check %then %put creat excel file;
I hope you get the idea
Hi @SASMom2
You can use a macro to run your code conditionally:
data mydata;
input Savings $ Saving_Amount;
cards;
ABC .
DEF .
GHI .
;
run;
%macro _savings ();
proc sql noprint;
select count(*) into:mis_amount from mydata where Saving_Amount=.;
quit;
%if &mis_amount = 3 %then %do;
proc print;/*<ODS TAGSETS statement>*/
%end;
%mend;
%_savings
Thank you for your reply. I think I am almost there except I want to say below.
%macro _savings ();
proc sql noprint;
select count(*) into:mis_amount from mydata where Saving_Amount=.;
quit;
%if &mis_amount = 0 %then %do;
got to the end of the code and exit.
%end;
%mend;
%_savings
thank you both for your reply. It worked!
Another possibility is to skip the macro stuff, and write to a temporary file instead:
filename tempsas temp;
set have;
where saving_amount is not null;
file tempsas:
put 'Proc Print data=have;run;';
stop;
run;
%include tempsas;
That way, if there are no non-missing values, nothing will be written to your temporary SAS file, and nothing will be executed with the %INCLUDE statement.
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 25. 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.