Goto Statement for conditional execution in SAS Macros


<<< Click here to go back 


Another way to write the macro as illustrated on previous page is :

%Macro understand_goto(Report_type);

%if &report_type. = Name %then %goto abc ;
%else %if &Report_type. = Subject  %then %goto xyz ;
%else %goto exit;

%abc:
proc sql ;
create table student_wise as
select name, sum(Marks_secured) as sum_secured, sum(full_marks) as sum_total
from class 
group by name
order by name;
quit;
%goto exit;

%xyz:
proc sql ;
create table subject_wise as
select Subject, count(name) as no_of_Students, 
sum(Marks_secured) as sum_secured, sum(full_marks) as sum_total
from class 
group by Subject
order by Subject;
quit;
%goto exit;

%exit:

%mend ;

%understand_goto(Subject);
%understand_goto(Name);

How the above code works :





Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.

No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.