From: UPHILG@UNC.BITNET (Philip Gallagher,(919)966-1065)
Newsgroups: bit.listserv.sas-l
Subject: Documented (?) use of SUBSTR?
Date: 15 Oct 92 14:37:00 GMT
Reply-To: "Philip Gallagher,(919)966-1065" <UPHILG@UNC.BITNET>
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU

Highly honoured SAS gurus,

One of my bright students surprised me yesterday with a syntactical
usage of the SUBSTR fcn that I had never seen before in SAS.  Although
it made sense to me that it would be a nice "feature" for SUBSTR to
have, I still don't remember having seen it documented anywhere.  Have
you?  Here it is:


 10         DATA FIXIT;
 11             SET MAKEIT.CONTAM;
 12             WHERE = INDEX(NAME, 'Ratface');
 13             IF (WHERE eq 0) THEN name = TRIM(name) || ', Evil Genius';
 14             ELSE SUBSTR(NAME,WHERE,8) = '';
 15         RUN;     #########################  !!!  No syntax error!!!!

 NOTE: DATA SET WORK.FIXIT HAS 5 OBSERVATIONS AND 2 VARIABLES. 1066 OBS/TRK.
 NOTE: THE DATA STATEMENT USED 0.06 SECONDS AND 204K.

 I have never before seen the SUBSTR fcn in SAS used except to return
 a character value to be used in an assignment stmnt or a comparison,
 etc.  I would never have guessed that it could be used to write
 over the portion of the first argument (NAME) described by the
 second and third arguments with the character string on the right
 hand side of the = sign.  (If I remember correctly, PL/1 does this,
 so I shouldn't be surprised that SAS can, too.)  Anyway, I've looked
 in my manuals, and I still can't find this documented.  I was amazed
 that there was no syntax error, so I tried a little program (appended),
 and found that there was still something new for me to learn about
 SAS.  :-)  Comments?

                         Phil Gallagher

11         SAS(R) LOG   OS SAS 5.18           MVS/XA JOB RATFACE2 STEP STEP2
0NOTE: COPYRIGHT (C) 1984,1988 SAS INSTITUTE INC., CARY, N.C.  27512, U.S.A.
 NOTE: THE JOB RATFACE2 HAS BEEN RUN UNDER RELEASE 5.18 OF SAS AT UNIVERSITY OF
0NOTE: CPUID   VERSION = FF  SERIAL = 175456  MODEL = 3090 .
0NOTE: SAS OPTIONS SPECIFIED ARE:
        SORT=4

 You are running SAS version 5.18 maintenance release of SAS. Any
 problems should be reported to UNCACS User Service at 919/962-0273.


 1
 2          *  THIS PROGRAM IS DESIGNED TO TEST THE NOVEL USE OF THE SUBSTR
 3             FUNCTION THAT EAB USED WITHOUT SYNTAX ERROR.
 4                             PNG, 15OCT92;
 5
 6          OPTIONS NOCENTER;
 7          title 'Dataset before cleaning';
 8          proc print data=makeit.contam;  var name;  run;
 NOTE: THE PROCEDURE PRINT USED 0.08 SECONDS AND 272K AND PRINTED PAGE 1.

 8                                                           title;
 9
 10         DATA FIXIT;
 11             SET MAKEIT.CONTAM;
 12             WHERE = INDEX(NAME, 'Ratface');
 13             IF (WHERE eq 0) THEN name = TRIM(name) || ', Evil Genius';
 14             ELSE SUBSTR(NAME,WHERE,8) = '';
 15         RUN;

 NOTE: DATA SET WORK.FIXIT HAS 5 OBSERVATIONS AND 2 VARIABLES. 1066 OBS/TRK.
 NOTE: THE DATA STATEMENT USED 0.06 SECONDS AND 204K.

 16
 17         PROC PRINT ; VAR  NAME where;
 18         title 'Dataset after decontamination'; run;
 NOTE: THE PROCEDURE PRINT USED 0.06 SECONDS AND 276K AND PRINTED PAGE 2.

 18                                                      title;
 NOTE: SAS USED 276K MEMORY.
0NOTE: SAS INSTITUTE INC.
       SAS CIRCLE
       PO BOX 8000
       CARY, N.C. 27512-8000



1Dataset before cleaning

 OBS NAME

  1  Philip N. Ratface Gallagher, Jr.
  2  Russell W. Ratface Helms
  3  Laura E. Ratface Helms
  4  Frank Yelverton
  5  Shannon Ratface Graham



1Dataset after decontamination

 OBS NAME                             WHERE

  1  Philip N.         Gallagher, Jr.  11
  2  Russell W.         Helms          12
  3  Laura E.         Helms            10
  4  Frank Yelverton, Evil Genius       0
  5  Shannon         Graham             9