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;

Monday, March 5, 2007

Find missing information

Missing information bugs me! Missing missing information bugs me more!!

However, there is an easy way to find variables with missing information. This method can be used for both continuous and categorical variables. Try the following after changing the keywords in color with your data specific names.
proc means data=trott1 NMISS N ;
var sbp dbp age smoking alcohol;
run;

More detailed information is available here.