Search code examples
sassas-macro

Conditionally print titles in SAS?


I want to display different titles for different variables that go through my macro.

%macro mplot(dsn,vn);
title1 'hey!';
%if "&vn"="" %then title2 "Ooos" justify=left;
%else title2 "Ooos &vn" justify=left;
title3 "this line";
%mend mplot;

%mplot(_avg);
%mplot(_avgs1,s1);

Ideal titles are:

hey!
Ooos
this line

hey!
Ooos s1
this line

But the output is

hey!
Ooos
title3 this line

hey!
Ooos s1
title3 this line

Solution

  • I solve it by adding a semicolon after it.

    %macro mplot(dsn,vn);
    title1 'hey!';
    %if "&vn"="" %then title2 "Ooos" justify=left;
    %else title2 "Ooos &vn" justify=left;;
    title3 "this line";
    %mend mplot;
    

    But I don't understand why an extra semocolon is needed.