Thursday, March 8, 2007

Prevent code from executing

My sas programs have a lot of code which I need intermittently but I don't need it to run everytime the program executes. Since, I need the code from time to time, I am reluctant to delete it.

There are various ways to prevent code from executing:
  1. /*comment out using asterisk slash*/ pieces of code enclosed by asterisk slash are treated as comments by sas and ignored.
  2. *comment using asterisk; pieces of code enclosed by asterisk and ';' are treated as comments and ignored by sas.
  3. %macro junk; enclose code as a macro; %mend; pieces of code enclosed as macro are ignored. This is extremely useful since method1 and 2 only work if there are no other comments in between. Junk can be replaced with any word.
e.g.

/* this is sample code */
proc means;
table age;
run;

/* this is second proc */
proc univariate;
var age;
run;


If this code needs to be ignored as a whole, method 1 would generate a error and method 2 will be tedious. This kind of code can be prevented from executing as follows:

%macro abcdg;
/* this is sample code */
proc means;
table age;
run;

/* this is second proc */
proc univariate;
var age;
run;

%mend;