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?
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.
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.
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
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.
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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.