楼主: jingju11
13624 52

[学习分享] 讲一讲 SAS 9.3 [推广有奖]

31
jingju11 发表于 2011-11-18 09:03:55
新安装sas ods被防火墙屏蔽。大家有没有建议?
京剧

32
jingju11 发表于 2011-11-21 23:11:19
* please label the variable first;
proc transpose data =graph out =graph_t;
  by crack;
   var Heavyplate Hulllate;
run;
ods graphics/width =8in height =4in;
proc sgplot;
   vbarparm category =crack response =col1/group =_label_ dataskin =pressed;
   yaxis grid values =(0.000 to 0.007 by 0.001) label =' ';
   xaxis display =(noticks) label =' ';
   keylegend /location =outside position =right title =' ';
run;
ods graphics/reset;

The above code is an illustration from a question. Some options are only limited to SAS 9.3.

JingJu vbar-b.bmp

vbar plot_j.jpg (95.67 KB)

vbar plot_j.jpg

vbar plot_j.jpg (90.31 KB)

vbar plot_j.jpg

33
jingju11 发表于 2011-11-25 06:48:42

Share a code about a question.

https://bbs.pinggu.org/thread-1264027-1-1.html


JingJu



data
Original;
input publishday: yymmdd10. price@@; format publishday date9.;
cards;
2011-8-2 20 2011-8-3 15 2011-8-4 14 2011-8-6 21 2011-8-7 19
2011-8-8 17 2011-8-9 22 2011-8-10 21
;
data a;
do _n_ =1 by 1 until(Eof);
      set original end =Eof;
      minD =min(minD, publishday); maxD =max(maxD, publishday);
   end;
   length d 8 price_c $12; format d date9.; keep d price_c; rename d =publishday price_c =price;
   if not missing(minD) then do d =minD to maxD;
      call missing(price_c);
      do p =1 to nobs;
         set original  point =p nobs =nobs;
         if publishday >d and publishday <=d +3 then price_c =catx(' ', price_c, price);
      end;
      output;
   end;
   stop;
run;






34
jingju11 发表于 2011-11-26 06:26:39
A SAS example code was modified by myslef to illustrate a customized FOREST plot from the question  in
https://bbs.pinggu.org/thread-1262816-1-1.html

JingJu
-------------------------------------------------------------------------
data meta(keep=Study Stat Value weight0)
    overall(keep=overall overallvalue)
     labels(keep=Study OddsRatio LowerCL UpperCl constant);
  input Study $1-16 OddsRatio LowerCL UpperCL Weight;
  weight0 =weight*10;
  length Stat $8;            
  format  OddsRatio LowerCL UpperCL 5.3;  
  output Labels;
  if Study eq "Overall" then do;
    OverallValue=OddsRatio;
    Overall="Overall";      
    output overall;
  end;
else do;
    weight=weight*.075;
    Stat="MIN";      
    Value=LowerCL;
    output meta;
    Stat="MAX";               
    Value=UpperCL;
    output meta;
    Stat="Q1";      
    Value= OddsRatio/(10 ** (weight/2));
    output meta;
    Stat="Q3";      
   Value= OddsRatio*(10 ** (weight/2));
    output meta;
    Stat="BOXWIDTH";
    Value=weight*3;
    output meta;
  end;
  datalines;
Modano  (1967)    0.590 0.096 3.634  1
Borodan (1981)    0.464 0.201 1.074  3.5
Leighton (1972)   0.394 0.076 2.055  2
Novak   (1992)    0.490 0.088 2.737  2
Stawer  (1998)    1.250 0.479 3.261  3
Truark   (2002)   0.129 0.027 0.605  2.5
Fayney   (2005)   0.313 0.054 1.805  2
Modano  (1969)    0.429 0.070 2.620  2
Soloway (2000)    0.718 0.237 2.179  3
Adams   (1999)    0.143 0.082 0.250  4
Truark2  (2002)   0.129 0.027 0.605  2.5
Fayney2  (2005)   0.313 0.054 1.805  2
Modano2 (1969)    0.429 0.070 2.620  2
Soloway2(2000)    0.718 0.237 2.179  3
Adams2   (1999)    0.143 0.082 0.250  4
Overall           0.328 0.233 0.462  .
;
run;



forest.png (129.5 KB)

forest.png

35
jingju11 发表于 2011-11-26 06:28:18
cont on last post...

proc template;
define statgraph ForestPlot_2Col;
  dynamic _pct;
  begingraph / designwidth=600px designheight=400px;
  entrytitle "Impact of Treatment on Mortality" / pad=(bottom=.025px);
    layout overlay / walldisplay=(fill)
                   yaxisopts=(display=none reverse=true offsetmin=_pct offsetmax=_pct)
                   xaxisopts=(type=linear offsetmin=0 offsetmax=0 linearopts =(tickvaluelist =(0 1 2 4) viewmin=-5 viewmax=4)
                                   label="                                                                    odds ratios");
      entry halign=left "             Study" "         sample" "       OR"  "        95%CI" halign=right  " " / location=outside valign=top ;
      scatterplot y=Study x=eval(constant*4) / markercharacter=Study;
      scatterplot y=Study x=eval(constant*3) / markercharacter=weight0;
      scatterplot y=Study x=eval(constant*2) / markercharacter=OddsRatio;           
               scatterplot y=Study x=eval(constant*1) / markercharacter=CI95;
      boxplotparm x=Study y=value stat=stat / orient=horizontal display=(fill notches);
      scatterplot x=OverallValue y=overall / markerattrs=(color=orange symbol=diamondfilled size=4pct);
               referenceline x=1. / lineattrs=(pattern=solid);
      referenceline x=.0 / lineattrs=(pattern=shortdash);
    endlayout;
  endgraph;
  end;
run;


36
jingju11 发表于 2011-11-26 06:29:06
proc template;
define Style foreststyle;
parent = styles.analysis;
style GraphFonts from GraphFonts
"Fonts used in graph styles" /
'GraphTitleFont' = (", ",10pt,bold)
'GraphLabelFont' = (", ",8pt)
'GraphValueFont' = (", ",7pt)
'GraphDataFont' = (", ",7pt);
end;
run;
title;
options nodate nonumber;
ods listing close;
ods rtf;
ods graphics / reset;
proc sgrender data=forest template=ForestPlot_2Col;
dynamic _pct=&pct;
run;
ods _all_ close; ods listing;

37
eardsion 发表于 2011-11-27 13:36:22
用9.2+ 9.1.3的路过

38
jingju11 发表于 2011-11-30 10:16:58
meta-analysis基本已经形成了自己比较完备的比较系统的理论和解决方案。不知道为什么sas没有做成一个过程,甚至一个集成的macro都没有?
京剧

39
jingju11 发表于 2011-12-1 01:45:09
An example of SAS BY-processing in model-fitting.
JingJu
---------------------------------------------------------------------------------------------------
/* Sort by plots variable in order to use BY statement in PROC*/
proc sort data =trees out =trees_s; by plots;
run;

******** FIT GENERALIZED NONLINEAR MIXED MODEL************* ;

proc nlmixed data=trees_s;
   by plots; *BY-processing =sub-setting the data set;
                 *BY-processing is enhanced by its efficiency;
   parms a=0.1 b=-0.002;                                                         
   eta = a + b*year;                                 
   p_ann_mort = exp(eta)/(1+exp(eta));                        
   p_ann_surv = 1-p_ann_mort;                                                
   p_surv = p_ann_surv**yr_interval;                                 
   p_mort = 1-p_surv;
   mean_mort = live_off*p_mort;
   ll=lgamma(1/alpha + n_dead) - lgamma(1 + n_dead) - lgamma(1/alpha)   + n_dead*log(alpha*mean_mort) - (1/alpha + n_dead)*log(1 + alpha*mean_mort);        
         * log likelihood function for negative binomial regression ;
   model n_dead ~ general(ll);
   predict live_off*p_mort out=predobs1;
   ods output ParameterEstimates =PEs; *create an output table PEs you needed;
run;

40
jingju11 发表于 2011-12-1 07:24:43
Even though, SAS provided an excellent KM-plot in its procedure, the customized KM-plots from assorted users are still of painstaking. Here I present my code for one of those.
JingJu

ods output  ProductLimitEstimates =lifetest_PEs;
proc lifetest data =LifeTest0 atrisk outsurv =outSurv1  ;
time time_m*censored(1);
run;
ods output clear;
data outSurv11;
   merge outSurv1 LifeTest_PEs(keep =time_m numberatrisk);;
   by Time_m;
run;

km-plot.png

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-12 06:23