全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学
2188 2
2010-03-22
Getting the IN operator to FUNCTION inside a SAS Macro

By: Perry Watts

Recommended Reading:
http://www.nesug.org/Proceedings/nesug09/cc/cc05.pdf
http://www.lexjansen.com/cgi-bin/xsl_transform.php?x=tmac&s=nesug_t&c=nesug

Related Link:
http://www.pinggu.org/bbs/thread-690356-1-1.html
By: bobguy



/* ---------------------------------------------------------------------------
Program : inFcn.sas
Author : Perry Watts
Date : 10Jun2009 14:39
Project : N09 Coder's Corner
Title : CC05: Getting the IN operator to FUNCTION inside a SAS® Macro
Path : Referenced in the SASAUTOS option in the CALLING program.
Purpose : Use inFcn to replicate the IN operator inside a macro.
Notes : Positional Keywords are being used to mimic operands assigned to
the IN operator.
------------------------------------------------------------------------ */
%macro InFcn (excerpt, matchlist);
%local TorF quotes;
%let quotes=%str(%'%");
%let excerpt = %nrbquote(%sysfunc(compress(&excerpt,""es")));
%let matchlist = %sysfunc(translate(&matchList,' ', ','));
%let matchlist = %nrbquote(%sysfunc(compress(&matchList,""es")));
%let TorF = %SYSFUNC(indexW(%upcase(&matchlist), %upcase(&excerpt)));
&TorF
%mend InFcn;
附件列表
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-3-22 09:45:40
算法看懂了,有些写法没看懂,copy下来运行有错,高手入指教啊
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-3-23 07:36:19
2# soporaeternus
Please try running following codes....

%macro InFcn (excerpt, matchlist);
%local TorF quotes;
%let quotes=%str(%'%");
%let excerpt = %nrbquote(%sysfunc(compress(&excerpt,"&quotes")));
%let matchlist = %sysfunc(translate(&matchList,' ', ','));
%let matchlist = %nrbquote(%sysfunc(compress(&matchList,"&quotes")));
%let TorF = %SYSFUNC(indexW(%upcase(&matchlist), %upcase(&excerpt)));
&TorF
%mend InFcn;

%macro enumerate;
data OneAlso;
length ingroup $
1;
%do i= 1 %to 10;
i=&i;
%if %infcn(&i, 1 4 5) %then %str(ingroup='Y';);
%else %str(ingroup='N';);
output;
%end;
run;
title1
'Data: OneAlso';
proc print data=OneAlso;
run;
%mend enumerate;
%enumerate
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群