<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: can i write my own function in sas? in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1188#M73</link>
    <description>But this can not use like a function in SAS.</description>
    <pubDate>Thu, 10 Aug 2006 13:03:32 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2006-08-10T13:03:32Z</dc:date>
    <item>
      <title>can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1184#M69</link>
      <description>In SAS,if I having a value to return to orther use, I only know that we can use macro variable. Can I use sas language to write my owner function with return value in SAS? Or write my owner macro function with return value in SAS?</description>
      <pubDate>Thu, 03 Aug 2006 12:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1184#M69</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-08-03T12:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1185#M70</link>
      <description>Hi Bill,&lt;BR /&gt;
&lt;BR /&gt;
Yes, you can write macros which operate as functions.  For example, suppose you need to compute the study day of a visit, and you have both the visit date and first day of study med (Day 1) on the record.  The following macro can be called as a function:&lt;BR /&gt;
&lt;BR /&gt;
%macro studyday (visdt, day1dt);&lt;BR /&gt;
&lt;BR /&gt;
visdt - day1dt + (visdt &amp;gt;= day1dt);&lt;BR /&gt;
&lt;BR /&gt;
%mend studyday;&lt;BR /&gt;
&lt;BR /&gt;
It could be invoked in a DATA step like this:&lt;BR /&gt;
&lt;BR /&gt;
data studydys;&lt;BR /&gt;
  set olddata;&lt;BR /&gt;
&lt;BR /&gt;
  studyday = %studyday(visdt, day1dt);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps,&lt;BR /&gt;
   Nancy</description>
      <pubDate>Fri, 04 Aug 2006 04:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1185#M70</guid>
      <dc:creator>Nancy_B</dc:creator>
      <dc:date>2006-08-04T04:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1186#M71</link>
      <description>Hi Nancy, thanks for your answer. This method sometime may be usefull, but I have a question, can't use this method. &lt;BR /&gt;
The problem is that: I have a table TRADING_DATE whith variable t_date means all the trading date, with the given date, I must give the last trading date before the given date. &lt;BR /&gt;
For example, the table have the record, 20030104,20030105,200306,20030109,20030110,....., with the given date 20030108, the last trading date before is 20030106. &lt;BR /&gt;
Can this writen as a function in SAS?</description>
      <pubDate>Sat, 05 Aug 2006 03:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1186#M71</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-08-05T03:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1187#M72</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Can you pls try the following code, may be this helps, if not pls let me know.. Check in your log file to the output. You can as well use the derived variable if required.&lt;BR /&gt;
&lt;BR /&gt;
Best Cheers&lt;BR /&gt;
Rao&lt;BR /&gt;
&lt;BR /&gt;
data trading_date;&lt;BR /&gt;
input tra_date $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
20030104&lt;BR /&gt;
20030105&lt;BR /&gt;
20030106&lt;BR /&gt;
20030109&lt;BR /&gt;
20030110&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
%macro checkbeforetd(chdate);&lt;BR /&gt;
%let chdate=&amp;amp;chdate;&lt;BR /&gt;
data trading_date(drop=tra_date);&lt;BR /&gt;
format trad_date ddmmyyp10.;&lt;BR /&gt;
length trad_date 5.;&lt;BR /&gt;
set trading_date;&lt;BR /&gt;
trad_date=input(put(tra_date,8.),yymmdd8.);&lt;BR /&gt;
put trad_date;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select max(trad_date) format ddmmyyp10. into :reqoutput from trading_date&lt;BR /&gt;
where trad_date lt &amp;amp;chdate;&lt;BR /&gt;
quit;&lt;BR /&gt;
%put &amp;amp;reqoutput;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%checkbeforetd('06Jan2003'd);</description>
      <pubDate>Tue, 08 Aug 2006 16:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1187#M72</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-08-08T16:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1188#M73</link>
      <description>But this can not use like a function in SAS.</description>
      <pubDate>Thu, 10 Aug 2006 13:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1188#M73</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-08-10T13:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1189#M74</link>
      <description>Writing your own function in SAS is problematic. You might consider writing functions in a language supported by SAS and registering them with SAS. See &lt;A href="http://support.sas.com/documentation/onlinedoc/base/91/proto.pdf" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/base/91/proto.pdf&lt;/A&gt; for more information.&lt;BR /&gt;
&lt;BR /&gt;
You will need to write your functions in C or C++. If you know the basics of either language, that's all you need for simple tasks.</description>
      <pubDate>Thu, 07 Dec 2006 00:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1189#M74</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-12-07T00:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1190#M75</link>
      <description>Bill ,&lt;BR /&gt;
&lt;BR /&gt;
Technically you cant really do this until Version 9.2 comes out.&lt;BR /&gt;
&lt;BR /&gt;
Now lets consider some non normal ways of getting what you want:&lt;BR /&gt;
&lt;BR /&gt;
Data One ;&lt;BR /&gt;
X = 10 ;&lt;BR /&gt;
Output ;&lt;BR /&gt;
&lt;BR /&gt;
X = 20 ;&lt;BR /&gt;
Output ;&lt;BR /&gt;
&lt;BR /&gt;
Run ;&lt;BR /&gt;
&lt;BR /&gt;
Options Mprint Mlogic Symbolgen ;&lt;BR /&gt;
%Macro Mult( Var = , Mlp = ) ;&lt;BR /&gt;
  %SysEvalF( &amp;amp;Var * &amp;amp;Mlp )&lt;BR /&gt;
%Mend Mult ;&lt;BR /&gt;
&lt;BR /&gt;
Data Need ;&lt;BR /&gt;
Set One ;&lt;BR /&gt;
MyNum = Resolve( '%Mult( Var = ' || Put( X , 8. -L ) || ', MLP = 10 )' ) ;&lt;BR /&gt;
&lt;BR /&gt;
Put X= MyNum= ;&lt;BR /&gt;
Run ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Here I use the resolve function to delay the execution of the macro %Mult until the data steps execution time. This allows one to pass variable X's values to the macro with each observation.  The Data Step releases control to the macro facility where it does the math and the macro facility passes back the new value and releases control back to the data step.</description>
      <pubDate>Fri, 15 Dec 2006 22:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1190#M75</guid>
      <dc:creator>TobyDunn_hotmail_com</dc:creator>
      <dc:date>2006-12-15T22:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1191#M76</link>
      <description>Many of the features in SAS and S that I like or dislike are similar to&lt;BR /&gt;
the last paragraph, in that they are consequences of the way in which the&lt;BR /&gt;
underlying package is organized.  They are not right or wrong, nor can they&lt;BR /&gt;
be `fixed', but in many particular instances one or the other can be&lt;BR /&gt;
very inconvenient.  Though GUI interfaces are a good thing in their own&lt;BR /&gt;
right, and are a big help to a certain class of user, they cannot undo some&lt;BR /&gt;
of these features:  PROC INSIGHT is not, nor is it even close to, a&lt;BR /&gt;
replacement for S graphics.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-----------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Dx&lt;BR /&gt;
----------------------------------------------&lt;BR /&gt;
&lt;A href="http://www.hotmail247.com"&gt;Hotmail Com&lt;/A&gt;-Hotmail Com</description>
      <pubDate>Fri, 24 Apr 2009 23:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1191#M76</guid>
      <dc:creator>naag</dc:creator>
      <dc:date>2009-04-24T23:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: can i write my own function in sas?</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1192#M77</link>
      <description>For consideration, I was able to execute the SAS RESOLVE function in SAS 9.1.3 SP4, using the sample code provided by TobyDunn.  I remember using this function in the past but never for numeric data calculations though.  Thanks to Toby for the extra idea.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sat, 25 Apr 2009 16:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/can-i-write-my-own-function-in-sas/m-p/1192#M77</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-25T16:23:39Z</dc:date>
    </item>
  </channel>
</rss>

