SAS Tips and Techniques

This is a collection of stuff that I've run across over the years


Code for writing out a counter every n observations;

%let n=100;
data _null_;
   do i=1 to 1000;
      if int(i/&n)=i/&n then put i=;
   end;
run;

I. Code for putting xx of xxxx in the title of a PROC PRINT

%let pickobs=25;

data check;
   set whatever;
run;

proc sql noprint;
   describe table dictionary.tables;
   select nobs into :n from dictionary.tables
      where libname="WORK" and memname="CHECK";
quit;

proc print data=check(obs=&pickobs);
   title2 "Selected observations (&pickobs of &n) from a dataset";
run;

II. The infamous Cowboy Hat plot;
goptions cback=black colors=(white cyan magenta gold yellow);

data hat;
   do x=-5 to 5 by .25;
      do y=-5 to 5 by .25;
         z=sin(sqrt(x*x + y*y));
         output;
      end;
   end;
run;
title1 c=white f=swiss 'The Cowboy Hat';
title2 h=2 angle=90 ' ';

proc g3d data=hat;
   plot y*x=z / ctop=yellow ctext=white;
run;

III. SAS macro for breaking apart a date variable.
%macro breakdn(date);
   ****************************************************************;
   * This macro breaks a date in the form of (MMDDYY) down into    ;
   * seperate month, day, and year variables.          RSM 6/89    ;
   ****************************************************************;

   month = floor(&date/10000);
   day   = mod(floor(&date/100),100);
   year  = mod(&date,100);
   if day in (.,0,99) & month not in (.,0,99) then day=15;
   yoh = year + (month-1)/12 + (day-1)/365.25; *Decimalized date;
%mend;

IV. Produce a table of contents with Dataset Name, Var, and Obs
options ps=77 ls=132 nodate pageno=1;
title 'FORD data files';
proc sql;
   describe table dictionary.tables;
   select memname, memlabel, nobs, nvar,  modate from dictionary.tables
      where libname='DT';
quit;

more to come...