DATA Step, Macro, Functions and more

Send Email if Nobs - if not, dont.

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Send Email if Nobs - if not, dont.

Hi. Ive made a macro that should send an email of there are observations in the dataset control.

Unfortunately it doens't wok. Can some of you guys see what im doing wrong?

 

 

%macro doit;

%let id=%sysfunc(open(Control));

%let NObs=%sysfunc(attrn(&id,NOBS));

%syscall set(id);

%do i=1 %to &NObs;

%let rc=%sysfunc(fetchobs(&id,&i));

 

filename mymail email

subject="Risk Control IRK: Violation in HQLA Concentration Risk"

to="SAN@RISK.DK"

 

 

data _null_;

file mymail;

put "HQLA";

put "- Paper : &papirnavn";

put "- Nominal : &NominalBase";

put "----------------------"; run;

 

run;

%

%end;

%let id=sysfunc(close(&id));

%mend;

 

%doit;

 

 


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 10,215

Re: Send Email if Nobs - if not, dont.

Retrieve the number from dictionary.tables:

%macro doit;

proc sql noprint;
select nobs into :nobs
from dictionary.tables
where libname = 'WORK' and memname = 'CONTROL';
quit;

%if &nobs ne 0
%then %do;

filename mymail email
  subject="Risk Control IRK: Violation in HQLA Concentration Risk"
  to="SAN@RISK.DK"
;

data _null_;
file mymail;
put "HQLA";
put "- Paper : &papirnavn";
put "- Nominal : &NominalBase";
put "----------------------";
run;

%end;
%mend;

%doit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 10,215

Re: Send Email if Nobs - if not, dont.

Retrieve the number from dictionary.tables:

%macro doit;

proc sql noprint;
select nobs into :nobs
from dictionary.tables
where libname = 'WORK' and memname = 'CONTROL';
quit;

%if &nobs ne 0
%then %do;

filename mymail email
  subject="Risk Control IRK: Violation in HQLA Concentration Risk"
  to="SAN@RISK.DK"
;

data _null_;
file mymail;
put "HQLA";
put "- Paper : &papirnavn";
put "- Nominal : &NominalBase";
put "----------------------";
run;

%end;
%mend;

%doit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

Re: Send Email if Nobs - if not, dont.

Posted in reply to KurtBremser

My solution ended like this. Thank you for your help. /Steffan

 

%macro doit;

 

proc sql noprint;

select nobs into :nobs

from dictionary.tables

where libname = 'WORK' and memname = 'CONTROL';

 

quit;

%if &nobs ne 0 %then

%do;

 

filename mymail email

subject="Risk Control IRK: Violation in HQLA Concentration Risk"

to="san@al-bank.dk"

attach= (&HQLA. content_type="application/xlsx")

CONTENT_TYPE="text/html";

 

ods listing close;

ods html body=mymail;

proc print data=work.control;

run;

ods html close;

ods listing;

%end;

%mend;

 

%doit;

 

Super User
Super User
Posts: 9,599

Re: Send Email if Nobs - if not, dont.

Simpler:

 

%macro doit();
filename mymail email...;
data _null_;
...;
run;
%mend doit;

data _null_; set sashelp.vtable (where=(memname="CONTROL")); if nobs=0 then call execute('%doit;'); run;

 

Super User
Posts: 6,756

Re: Send Email if Nobs - if not, dont.

It looks like you are complicating the problem.  Macro language is not needed (except perhaps for the macro variables &PAPIRNAVN and &NOMINALBASE).  Consider this DATA step:

 

data _null_;

set control;

file mymail;

put .......................................;

stop;

run;

 

When there are zero observations, the SET statement halts the DATA step.  When there are observations, the rest of the DATA step proceeds once, then stops.

Super User
Super User
Posts: 9,599

Re: Send Email if Nobs - if not, dont.

Posted in reply to Astounding

Nice, I had never thought of using the set that way.  

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 95 views
  • 6 likes
  • 4 in conversation