home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / bit / listserv / sasl / 5546 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.5 KB  |  75 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!spool.mu.edu!darwin.sura.net!paladin.american.edu!auvm!PHPDLS1.EM.CDC.GOV!RJF2
  3. Encoding: 71 TEXT
  4. X-Mailer: Microsoft Mail V3.0
  5. Message-ID: <2B4BBB6E@router.em.cdc.gov>
  6. Newsgroups: bit.listserv.sas-l
  7. Date:         Thu, 7 Jan 1993 09:13:00 EST
  8. Reply-To:     rjf2@PHPDLS1.EM.CDC.GOV
  9. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  10. From:         rjf2@PHPDLS1.EM.CDC.GOV
  11. Subject:      user-defined macro functions?
  12. Comments: To: SAS-L@uga.cc.uga.edu
  13. Lines: 60
  14.  
  15. content      : Response
  16. summary      : user-defined function written in macro
  17. rlse/platform: V6.07 / MVS
  18. Ron Fehd     :                SMTP:BitNet:    <rjf2@phpdls1.em.cdc.gov>
  19.               Centers for Disease Control
  20.               1600 Clifton Rd  MS:G25         FAX  : 404/639-1778
  21.               Atlanta, GA 30333  USA          phone: 404/639-1707
  22. ????????????????????????????????????????????????????????????????????
  23. From:         John Mark Williams <jmw@TASMAN.CC.UTAS.EDU.AU>
  24. Subject:      user-defined macro functions?
  25. Hi all,
  26. Is is possible to write a user-defined function in SAS? Something that would
  27. operate like:
  28. %let x = %amacro;
  29. where amacro will return a value. Alternatively what about
  30. %amacro(x)
  31. where the value of x is altered within the macro and is available outside it.
  32. Many thanks,
  33. --
  34. John M Williams,
  35. School of Health Sciences, University of Tasmania
  36. J.M.Williams@med.utas.edu.au
  37. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  38. ah, yes, string processing, I love it!
  39.  
  40. here is a macro for the xor operator, which I wrote for &SYSVER le 5.18;
  41. note that V6 has the bxor operator (bit-wise xor) which works differently
  42. than this macro.
  43.  
  44. %MACRO XOR(COND1,COND2);/*evaluation yields boolean value in (0,1)*/
  45.  
  46.     (   (    &COND1 and not (&COND2)
  47.      or (not &COND1 and     (&COND2) )                     %MEND;
  48.  
  49. /*NB: Note Well: no semicolons in this macro!
  50.   caveat: neither COND1 nor COND2 may contain an equals sign: '='
  51.           use operator 'eq' and it works fine*/
  52.  
  53. usage in data step:
  54.  
  55. DATA;
  56.   set <something>;
  57.   if %XOR(A,B) then <do something1>;
  58.   if %XOR(C eq D,D gt E) then <do something2>;
  59.   if %XOR(first.ID,last.ID);
  60.   /*try this with F & G in (0,1,2,3)*/
  61.   Var_xor  = %XOR(F,G);
  62.   Var_bxor = bxor(F,G);
  63.  
  64. a macro (procedure or subroutine) to pad a char var with dots
  65. %MACRO SPAC2DOT(VAR);
  66. &VAR = translate(&VAR.,'.',' ');                            %MEND;
  67.  
  68. usage in data step:
  69.  
  70. DATA;
  71.   set <something>;
  72.   %SPAC2DOT(Char6);
  73.  
  74. happy crunching!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!
  75.