You need a semicolon to end the macro language statement:
%if "&clase1"="SEXO_1F" %then format &clase1 SEXO.;; run; %mend;
Mind the order of colours! Red semicolon and then the blue one,
the same way you would "close" the put statement:
%put some text to print ; /* this semicolon ends the %put statement */
If you have a 4GL code which contains semicolons you basically have to use %do;-%end; block
This will fail:
%macro p1(datos,clase1,clase2);
data _nulL_;
%if "&clase1"="SEXO" %then
format &clase1 dollar12.2; &clase1=17; y=42; ;
run;
%mend;
%p1(people,SEXO,EDAD);
because the semicolon after " dollar12.2 " is interpreted as %if-%then statement end;
Log looks like this:
1 %macro p1(datos,clase1,clase2);
2
3 data _nulL_;
4
5 %if "&clase1"="SEXO" %then
6 format &clase1 dollar12.2; &clase1=17; y=42; ;
7
8 run;
9 %mend;
10
11 %p1(people,SEXO,EDAD);
NOTE: Line generated by the invoked macro "P1".
6 &clase1=17; y=42; ; run;
-
85
76
ERROR 85-322: Expecting a format name.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
But if you add %do;-%end; block everything works fine:
%macro p1(datos,clase1,clase2);
data _nulL_;
%if "&clase1"="SEXO" %then
%do;
format &clase1 dollar12.2; &clase1=17; y=42;
%end;
run;
%mend;
%p1(people,SEXO,EDAD);
Log:
1 %macro p1(datos,clase1,clase2);
2
3 data _nulL_;
4
5 %if "&clase1"="SEXO" %then
6 %do;
7 format &clase1 dollar12.2; &clase1=17; y=42;
8 %end;
9
10 run;
11 %mend;
12
13 %p1(people,SEXO,EDAD);
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Remember all the "hardness" of macro programming is that your code (the macro language statements) and your data (the 4GL code) are mixed together in one place (a text file with code), so you have to have precise rules to tell SAS which is which.
Bart
... View more