楼主: jsglf
2223 3

请教高手:一段SAS宏代码的意思? [推广有奖]

  • 0关注
  • 0粉丝

高中生

45%

还不是VIP/贵宾

-

威望
0
论坛币
228 个
通用积分
27.5598
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
716 点
帖子
15
精华
0
在线时间
39 小时
注册时间
2008-2-5
最后登录
2024-4-21

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

小弟是SAS新手,对下面标洋红色的这段SAS宏代码不是很理解,请高手帮忙指点一下,谢谢!

%macro OneContPlot(data=dsname,x=x,y=y,numy=3,const=0.5,nbhd=50,plot=1);
/*--------------------------------------------------------------------------
  A macro extension of SAS Usage Note 37944 to continuous covariates.  Plots
  the empirical logits defined using the NBHD/2 observed X values preceding
  and following each observation against the levels of a single continuous
  var, then smooths the result.  Called by the %EmpiricalLogitPlot macro.

  data=  name of the input data set.
  x=     name of the single continuous covariate.
  y=     name of the response variable. y=1,2,3...
  numy=  number of levels of the response.
  const= small value in case of zero cells.
  nbhd=  total number of neighbors.
  plot=  1=create the plot
  --------------------------------------------------------------------------*/
ods graphics / antialiasmax=100000;
data temp;  
   set &data;
proc sort data=temp;  
   by &x &y;  
%let Full=%eval(&nbhd);
%let Fullp1=%eval(&nbhd+1);
%let Half=%eval(&nbhd/2);
%let numym1=%eval(&numy-1);
data temp2;  
   set temp;
   retain %do i=1 %to &numy; sum&i %end; 0;
   lagx= lag&Full(&x);  
   lagHalfx=lag&Half(&x);  
   lagy=lag&Fullp1(&y);
   %do i=1 %to &numy; sum&i=sum&i+(&y=&i); %end;
   if (lagy^=.) then do;
      %do i=1 %to &numy; sum&i=sum&i-(lagy=&i); %end;
   end;
data temp;
   set temp2;  
   if (_n_<&Full) then delete;
data temp2;  
   set temp;
   const=%sysevalf(&const+0);
   x=lagHalfx;
   group="&x";
   %do i=1 %to &numym1; %let j=%eval(&i+1);
   d&i=log((sum(of sum1-sum&i)+const) / (sum(of sum&j-sum&numy)+const));
   %end;
   keep d1-d&numym1 group x;                                             
run;
%if %eval(&plot eq 1) %then %do;
proc sgplot;
   %do i=1 %to &numym1;  
   loess y=d&i x=x / smooth=0.2 legendlabel="Pr(&y<=&i)"
                     lineattrs=GraphData&i(thickness=3px)
                     markerattrs=(color=gray);
   %end;
   yaxis values=(-5 to 5) label="Cumulative Probability";
   keylegend %do i=1 %to &numym1; "series&i" %end;;   
run;
%end;
%mend;

二维码

扫码加我 拉你入群

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

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

关键词:SAS宏 请教高手 observation Continuous covariates marco

沙发
fisher163 发表于 2015-6-14 23:12:12 |只看作者 |坛友微信交流群
I guess you might not be very much familiar with lag function.
retain statement is to hold the previous value
lag function is to specify the lagged value, detalied please refer to below link.
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212547.htm

使用道具

藤椅
jsglf 发表于 2015-6-14 23:44:06 |只看作者 |坛友微信交流群
fisher163 发表于 2015-6-14 23:12
I guess you might not be very much familiar with lag function.
retain statement is to hold the pre ...
Thanks for answering my question.
By the way, could you please tell me what is the meaning of  sum&i  in the retain statement?
Appreciate it!

使用道具

板凳
playmore 发表于 2015-6-15 08:33:36 |只看作者 |坛友微信交流群
jsglf 发表于 2015-6-14 23:44
Thanks for answering my question.
By the way, could you please tell me what is the meaning of  su ...
你看看temp2的数据就好了
sum1,sum2和sum3是用来保存前n个观测的和的

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 19:17