标题: SAS自定义函数 [打印本页] 作者: shiyiming 时间: 2007-8-23 19:17 标题: SAS自定义函数 SAS 9.1中的proc fcmp过程步就是可以用来自定义函数的
有兴趣的朋友可以一起探讨一下作者: shiyiming 时间: 2007-11-30 10:31 标题: Re: SAS自定义函数 Function/Subroutine Declarations
[code:1xs57qfa]proc fcmp outlib= sasuser.MySubs.MathFncs;
subroutine inverse( in, inv );
outargs inv;
if in = 0 then inv = .;
else inv = 1/in;
endsub;
function day_date( indate, type $ );
if type = "DAYS" then wkday = weekday(indate);
if type = "YEARS" then wkday = weekday(indate*365);
return( wkday );
endsub;
run;[/code:1xs57qfa]
SAS Global Option CMPLIB
[code:1xs57qfa]cmplib = sasuser.funcs;
cmplib = (sasuser.funcs work.functions mycat.funcs);
cmplib = sasuser.func1 - sasuser.func10;[/code:1xs57qfa]
<!-- m --><a class="postlink" href="http://support.sas.com/documentation/onlinedoc/base/91/fcmp.pdf">http://support.sas.com/documentation/on ... 1/fcmp.pdf</a><!-- m -->作者: shiyiming 时间: 2008-10-9 17:05 标题: Re: SAS自定义函数 为什么我从PDF上面直接拷贝下来的粒子到PC上都不能正常运行呢?总是抱错说找不到我自定义的函数,望不吝赐教,谢谢作者: shiyiming 时间: 2008-10-9 17:33 标题: Re: SAS自定义函数 首先,要确认只有SAS 9.1以上版本才有这个功能。
其次,把错误log贴上来看看,让大家看log分析才是好习惯。作者: shiyiming 时间: 2008-10-10 08:27 标题: to horse1 sometimes it's just that one double quotes become 2 single quotes after copy & paste
anyway, I may be wrong作者: shiyiming 时间: 2008-10-10 09:51 标题: Re: SAS自定义函数 我的SAS是9.1.3版的,下面是程序运行的log
1 proc fcmp outlib=work.funcs.math;
2 function test() $ 12;
3 length x $ 25;
4 length z $ 30;
5 x = '1234';
6 if x = '1234' then
7 return(x);
NOTE: Character value converted to numeric at line 7 column 8.
8 else
9 return(z);
NOTE: Character value converted to numeric at line 9 column 8.
10 endsub;
11 run;
NOTE: Function test saved to catalog work.funcs.math.
NOTE: PROCEDURE FCMP used (Total process time):
real time 0.15 seconds
cpu time 0.09 seconds
12 options cmplib = work.funcs;
13 data _null_;
14 y = test();
----
68
ERROR 68-185: The function TEST is unknown, or cannot be accessed.
15 put y=;
16 vlen = vlength(y);
17 put vlen=;
18 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds作者: shiyiming 时间: 2008-10-10 17:38 标题: Re: SAS自定义函数 那个PDF文档写的很清楚吧,DATA STEP里能调用吗?呵呵呵。所以传个log上来,一看就知道哪里错了。
[quote:c6b5xg52]The following SAS procedures allow the use of the functions and subroutines created
by FCMP:
• CALIS
• COMPILE
• DISTANCE
• GA
• GENMOD
• MODEL
• NLIN
• NLMIXED
• NLP
• PHREG
• RISK DIMENSIONS
• ROBUSTREG
• SIMILAR
• SYLK[/quote:c6b5xg52]作者: shiyiming 时间: 2008-10-10 17:56 标题: Re: SAS自定义函数 我还是不太明白,是说自定的函数不能在data步中使用吗? 可是为什么pdf上面例子就是在data步中使用啊?作者: shiyiming 时间: 2008-10-10 18:01 标题: Re: SAS自定义函数 真是的,我提供的PDF文档上写的很清楚了,怎么还说不明白啊?这么简单的英语没理由看不懂啊?所列的中没有DATA STEP就是不能用啊!!! <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: -->