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

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!munnari.oz.au!spool.mu.edu!sol.ctr.columbia.edu!howland.reston.ans.net!paladin.american.edu!auvm!COMPUSERVE.COM!75046.1627
  3. Message-ID: <930107145304_75046.1627_CHI55-1@CompuServe.COM>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Thu, 7 Jan 1993 09:53:04 EST
  6. Reply-To:     Michael Davis <75046.1627@COMPUSERVE.COM>
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         Michael Davis <75046.1627@COMPUSERVE.COM>
  9. Subject: Re: user-defined functions
  10. Comments: To: SAS-L@uga.cc.uga.edu
  11. Lines: 52
  12.  
  13. -----------------------------------------------------------------------
  14. CONTENT:    response to question re: user-defined macro functions
  15. SUMMARY:    use FORMAT procedure plus PUT, INPUT functions
  16. REL/PLTF:   all
  17. E-ADDR:     0002395748@mcimail.com
  18. P-ADDR:     BC&BS OF Conn., 370 Bassett Road, North Haven, CT 06473
  19. PHONE:      (203)-985-7187
  20. FAX:        (203)-985-7030
  21. -----------------------------------------------------------------------
  22.  
  23. John Mark Williams <jmw@tasman.cc.utas.edu.au> asked if it was
  24. possible to write a user-defined function in SAS?  Well, John, it
  25. is and you do not need to use macros.  Simply combine the FORMAT
  26. procedure with either an INPUT or PUT function.  For example,
  27.  
  28. proc format;
  29.     value $JMW
  30.     'A'= 'YES'
  31.     other= 'NO'
  32.     ;
  33. run;
  34. data JMW;
  35.     input @1 test $1.;
  36.     cards;
  37. A
  38. B
  39. ;
  40. data _null_;
  41.     set JMW;
  42.     x= put(test,$JMW.);
  43.     put x;
  44. run;
  45.  
  46. In this example, the PUT function assigns a value to the variable
  47. x according to the translation table created by the user-defined
  48. function $JMW.  If you run the above program and look at the log,
  49. you will see that YES was assigned to X when TEST equaled A for the
  50. first observation and NO was assigned to X when TEST equaled B.
  51.  
  52. As a strategy, consider using the LIBRARY option so that you can
  53. reuse formats.  Another benefit is that if you change the format,
  54. all programs that use it are updated.
  55.  
  56. If you are using Release 6.07 or a later release, you may wish to
  57. create your format using a data set as input.  Earlier releases
  58. could do this with the use of macros but it was more complicated.
  59. It is usually quicker to create and maintain complicated formats
  60. using a data set as input.
  61.  
  62.  
  63. Distribution:
  64.   >internet: SAS-L@uga.cc.uga.edu
  65.