0

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
Lovnlust
  • 1,507
  • 3
  • 29
  • 53

1 Answers1

0

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.

Lovnlust
  • 1,507
  • 3
  • 29
  • 53
  • Perhaps some code you submitted earlier was missing a semicolon, and this finally allowed your SAS session to 'catch up' on semi-colons. – Robert Penridge Jan 16 '15 at 15:28
  • 2
    The "extra" semicolon is needed to end the title statement. The %IF statement ends with a semicolon. The %else statement ends with a semicolon. When the macro executes, it will generate title2 "Ooos" without a semicolon to end the title statement. The extra semicolon ends the title statement. – Quentin Jan 17 '15 at 04:27
  • Semicolons cause less confusion if you add extra %do; - %end; pears: `%if "&vn"="" %then %do;` `title2 "Ooos" justify=left;` `%end;` `%else %do;` `title2 "Ooos &vn" justify=left;` `%end;` – Dirk Horsten Jan 24 '15 at 15:06