BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kelroy22
Fluorite | Level 6

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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;
Kelroy22
Fluorite | Level 6

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;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

 

Astounding
PROC Star

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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