Tuesday 3 May 2011

NOTE: PROC DELETE and Other Hits From the Past

Thanks for all your good wishes with regard to passing the magic 300 subscribers watermark. Needless to say, the number plummeted the day after I posted! I feel sure it'll recover in time.

Thanks also to those who have responded to other recent posts. @LaurieFleming (Wellington, NZ) has tweeted a few times, including a response to my "NOTE: Undocumented Features - Use Them at Your Peril!" post. Laurie said:
Interesting! I'd apply your caveat to the deprecated features as well like proc delete - use it, sure, but document it!
Well said Laurie. I confess to using PROC DELETE occasionally, because its syntax is neater than PROC DATASETS, but never in production code.

It feels like PROC DELETE has been part of the SAS system since the beginning (I feel sure somebody can verify the accuracy of this assertion), but I don't remember a time when I considered it supported. It has remained a part of the SAS system, but undocumented and unsupported. Its syntax (see below) is non-standard, i.e. there's no DATA parameter.

proc delete MYLIB.MYDATA;

The equivalent (documented and supported) use of PROC DATASETS necessitates more typing:

proc datasets lib=MYLIB nolist;
  delete MYDATA;

One clear advantage of PROC DATASETS is its ability to delete multiple data sets whose name uses the same prefix, e.g. MYLIB.MYDATAKENT, MYLIB.MYDATASURREY, MYLIB.MYDATASUSSEX. The colon on the end of the data set name prefix does the trick:

proc datasets lib=MYLIB nolist;
  delete MYDATA: ;

I used this technique in the "tidy" feature of the test harness macro that I described in my SAS Global Forum paper this year.

Whilst I'm strolling along memory lane, and talking of deprecated PROCs, do you remember PROC SPELL and PROC EDITOR? The copy of SAS 9.2 M3 that I have in front of me on Windows 7 (64 bit) still runs code with these PROCs.

PROC SPELL is described neatly on sasCommunity.org. It allows you to check an input text file for matches with a specified file of words, i.e. a dictionary.

PROC EDITOR has no entry on sasCommunity.org. It allows programmatic editing of a data set.

data class;
  set sashelp.class;

proc editor data=work.class;
  /* Row ptr starts at 1.  */
  /* Change NAME in row 4. */
  /* Length of NAME is $8, */
  /* so no "Katherine".    */
  down 3;
  replace name="Kate";

  /* Now change NAME in row 6. */
  /* No quotes, defaults to all-caps */
  down 2;
  replace name=Wills;

  /* Finally, search NAME */
  string name;
  search 1,last "Philip";
  replace age=90; /* dob=10-jun-1921 */
                  /* One day after mine (different year!) */
The example code shows the most that I can remember of the syntax. It loosely implements Microsoft DOS's Edlin editor. The example code moves the pointer (DOWN) and replaces values of specified variables (REPLACE); the code also searches a specified variable (across a specified range of rows).

An interesting PROC. Its functionality is easily reproduced in DATA step, so its loss is not great.