BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Calcite | Level 5
Thank you all! @art297 that was my conclusion as well and I fixed it accordingly! Thank you all again so much. I really appreciate you taking the time to help me with this.
Super User

@art297 wrote:

I ran the code that @Reeza posted, which included the embedded *  ; comments, and it appeared to run perfectly.


In fact, her example data showed a flaw that should be fixed in @Amerie's code. The conditions don't trap values of 0, thus they're incorrectly recoded as 2 (i.e., representing GE 14)


Art, CEO,



This is very specific to the BRFSS (Behavioral Risk Factor Surveillance System) data. The survey data question collection coding does not allow 0 to be entered for this data point (and most others). The code value of 88 on the first test is for respondent answers of 0 or None.

The data is "trapped" in effect for that value by CDC before the analysts receive the data.

Which is also why none of the other values between 30 and 77, 77 to 88 or 88 to 99 are tested or coded.


(Former BRFSS data collection contractor and occasional analyst)

Super User

@Astounding it works fine. However, adding apostrophe's to comments within a macro using * is a good way to introduce random errors into your work. 

Super User Tom
Super User

The problem actually happens in macro code.  If you try to use statement style comments (* ... 😉 between macro %if/%else it will confuse the connection between the %if and the %else. Macro comments or block comments are ok there.

2311  %macro test1(x);
2312  %if x1=1 %then %do; ageX=1; %end;
2313   * statement comment ;
2314  %else %do ;  ageX=0; %end;
ERROR: There is no matching %IF statement for the %ELSE.
ERROR: A dummy macro will be compiled.
2315  %mend test1;

2316  %macro test2(x);
2317  %if x1=1 %then %do; ageX=1; %end;
2318   %* macro comment ;
2319  %else %do ;  ageX=0; %end;
2320  %mend test2;

2321  %macro test3(x);
2322  %if x1=1 %then %do; ageX=1; %end;
2323   /* block comment */
2324  %else %do ;  ageX=0; %end;
2325  %mend test3;



@Reeza wrote:

@Astounding wrote:



For most of the errors, the mistake is right there in your code.  The comment statements throw off the IF/THEN/ELSE logic.  You can't have a comment statement before an ELSE statement ... it removes the connection with the previous IF condition.  You could change all your comments statements:


* Not like this;

/* but like this instead */


Embedded comments won't disconnect the IF THEN from the subsequent ELSE IF.


But the first error is still a mystery, and depends on what came prior to that in the program.

I don't think that's true, you can have comments within the IF/ELSE IF statements regardless of type. 




Super User

@Tom Yes, that's correct. If you use *; style comments in a macro you'll likely have issues. You need to use either:




/**/ to comment in a macro. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 19 replies
  • 8 in conversation