again Macro with Data steps

Reply
Occasional Contributor Pan
Occasional Contributor
Posts: 10

again Macro with Data steps

Can someone tell me the difference between the following two sets of codes. This error drive me crazy.

1: Log:

461  %MACRO PRO(YR);

462  %let P_YR=%eval(&YR-1);

463  %put &P_YR;

464  Data Det_&YR culvert_&YR;

465  Set Bridge_&P_YR;

466  Format Maintenance_Status $ 20.0;

467

468  if District='Bismarck' then output culvert_&YR;

469  else output Det_&YR;

470

471  run;

472

473  %mend Pro;

474  %Pro(2013);

2012

NOTE: Variable Maintenance_Status is uninitialized.

NOTE: There were 2498 observations read from the data set WORK.BRIDGE_2012.

NOTE: The data set WORK.DET_2013 has 2146 observations and 74 variables.

NOTE: The data set WORK.CULVERT_2013 has 352 observations and 74 variables.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

2:log:

475  %macro Project(YR);

476  %let P_YR=%sysevalf(%eval(&YR-1));

477  *%put &P_YR;

478  Data Bridge_&YR Culvert_&YR;

479  Set Bridge_&P_YR;

480  format Maintenance_Status $ 20.0;

481

482  if District='Bismarck' then output Culvert_&YR;

483  else output Bridge_&YR;

484

485  *Treatment_&YR=Maintenance_Status;

486

487  run;

488  %mend Project;

489  %Project(2013);

2012

NOTE: Line generated by the invoked macro "PROJECT".

3     Data Bridge_&YR Culvert_&YR; Set Bridge_&P_YR; format Maintenance_Status $ 20.0;  if

                                                          ---

                                                        180

3  ! District='Bismarck' then output Culvert_&YR; else output Bridge_&YR;

3  ! *Treatment_&YR=Maintenance_Status;  run;

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "PROJECT".

3     Data Bridge_&YR Culvert_&YR; Set Bridge_&P_YR; format Maintenance_Status $ 20.0;  if

                                                                                        ------

                                                                                        180

3  ! District='Bismarck' then output Culvert_&YR; else output Bridge_&YR;

3  ! *Treatment_&YR=Maintenance_Status;  run;

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "PROJECT".

3     Data Bridge_&YR Culvert_&YR; Set Bridge_&P_YR; format Maintenance_Status $ 20.0;  if

                                                                                                                                               --

                                                                                                                                              180

3  ! District='Bismarck' then output Culvert_&YR; else output Bridge_&YR;

3  ! *Treatment_&YR=Maintenance_Status;  run;

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the invoked macro "PROJECT".

3     Data Bridge_&YR Culvert_&YR; Set Bridge_&P_YR; format Maintenance_Status $ 20.0;  if

3  ! District='Bismarck' then output Culvert_&YR; else output Bridge_&YR;

                                                                           ----

                                                                          180

3  ! *Treatment_&YR=Maintenance_Status;  run;

ERROR 180-322: Statement is not valid or it is used out of proper order.

Super User
Posts: 11,343

Re: again Macro with Data steps

Since the obvious change is wrapping an %eval() withing %sysevalf one wonders what the latter is supposed to do that the simple %eval didn't.

Your output shows that you %put the value of the macro variable BUT the immediately preceding code shows an attempt to comment that out i.e.

*%put ... ;

You may not have a properly compiled version of the macro.

Check the online help for %* for and example of issues about using the * ; style comments inside macro definitions.

Occasional Contributor Pan
Occasional Contributor
Posts: 10

Re: again Macro with Data steps

Wow, you are right. It is because of *; usage in Macro. Thanks a lot!

Super User
Super User
Posts: 7,042

Re: again Macro with Data steps

Statement style comments (*...Smiley Wink are valid to use inside of a macro definition, but just remember that the macro will treat them the same as any other standard SAS statement that you want the macro to generate.

They can eliminate the need to turn on MLOGIC or SYMBOLGEN and so are very useful for making your SAS log more readable.

%macro test(x);

%if &x > 0 %then %do;

* For positive values .... ;

...

%end;

%else %do;

* For negative values .... ;

...

%end;

%mend test ;

%test(5);

MPRINT(TEST):  * For positive values .... ;

MPRINT(TEST):  ....

Ask a Question
Discussion stats
  • 3 replies
  • 210 views
  • 0 likes
  • 3 in conversation