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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 1598 views
  • 6 likes
  • 4 in conversation