BookmarkSubscribeRSS Feed
SASMom2
Fluorite | Level 6

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.

 

SavingsSaving_Amount
ABC 
DEF 
GHI 

 

 

How do I program this?

 

Thanks for your help.

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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

ed_sas_member
Meteorite | Level 14

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
SASMom2
Fluorite | Level 6

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

SASMom2
Fluorite | Level 6

thank you both for your reply. It worked!

s_lassen
Meteorite | Level 14

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2047 views
  • 0 likes
  • 4 in conversation