BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
awesome_opossum
Obsidian | Level 7

So I'm really thinking about this in how to adapt someone else's code. 

 

The problem is there are both substantive comments, as in explanations, as well as code that is commented out.  Therefore I cannot do a global ctrl+shift+?, because the substantive/explanation comments would also be released into the program, faltering a full run. 

 

Is the only option actually to go through each step and comment/uncomment as needed, rather than being able to observe the data/print that goes along with each analytic step in the full run?  I understand even with a full run, there may or may not be issues around recursive table naming, etc, but I am not concerned about that in this case. 

 

It would be useful if there is two forms of comment, one for code and one for substantive comments? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

SAS has three forms of comments.

 

STATEMENT comments that start with * and end with ;.  These are just like any other statement in your program.

 

MACRO comments that start with %* and end with ;.  These are just like any other macro statement in your program.

 

BLOCK comments that start with /* and end with */.  These can be around multiple statements or just around part of one statement. 

 

If you are feeling you need more you can use the trick of converting some block of code into a MACRO DEFINITION and then just never call the macro you defined.   For example by adding the statement %MACRO XXX; before the first statement and the statement %MEND; after the last statement.

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

SAS has three forms of comments.

 

STATEMENT comments that start with * and end with ;.  These are just like any other statement in your program.

 

MACRO comments that start with %* and end with ;.  These are just like any other macro statement in your program.

 

BLOCK comments that start with /* and end with */.  These can be around multiple statements or just around part of one statement. 

 

If you are feeling you need more you can use the trick of converting some block of code into a MACRO DEFINITION and then just never call the macro you defined.   For example by adding the statement %MACRO XXX; before the first statement and the statement %MEND; after the last statement.

WarrenKuhfeld
Rhodochrosite | Level 12

You forgot one style, although I don't know why anyone would ever want to use it. Comments can begin with COMMENT.

 

 
1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         comment this is an obscure comment;
 70         comment print some sample data;
 71         proc print data=sashelp.class;
 72         run;
 
 NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.01 seconds
       user cpu time       0.02 seconds
       system cpu time     0.00 seconds
       memory              1131.87k
       OS Memory           20640.00k
       Timestamp           08/26/2023 12:12:22 PM
       Step Count                        24  Switch Count  0
       Page Faults                       0
       Page Reclaims                     477
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           8
       
 
 73         comment now we are done;
 74         
 75         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 85         
 
Quentin
Super User

As Reeza showed there are several different types of comments that can be used.

 

But I'm curious what leads you to want to do a global uncomment?  I don't think I've ever wanted to uncomment all the comments in a program.

 

If you are frequently using comments to turn sections of code on and off, that would probably be better done with the macro language or some other way to conditionally execute code.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
awesome_opossum
Obsidian | Level 7

All really great answers!  Thank you so much!

 

Is there no close topic option unless you signify an answer?  Wow. 

 

I guess we'll work that one out tomorrow.  

ballardw
Super User

If by "signify and answer" you mean accept a response as the correct solution then that does not "close" anything either.

 

Not infrequently a solution brings up an additional question by the question poster. So the thread is still open.

PaigeMiller
Diamond | Level 26

You can use the macro statement %if 0 %then %do; as a form of comment block, as %if 0 is never true, so whatever is inside the %do will never execute. Don't forget to put and %end; statement at the end of the commented block. Example:

 

%if 0 %then %do;
data abc;
    set have;
    z=arcos(y); /* This uses the Paige Miller "Connifulator" method */
run;
%end;

 

Since this macro %IF is allowed in open code (does not have to be inside a macro), you can use this anywhere.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 7 replies
  • 895 views
  • 5 likes
  • 7 in conversation