sas定量數據描述常用過程-數據探索 PROC MEANS/FREQ/UNIVARIATE


index: proc means | proc freq|proc univariate

 

/*******************proc means*********************/

PROC MEANS <option(s)> <statistic-keyword(s)>;

BY <DESCENDING> variable-1 <… <DESCENDING>variable-n><NOTSORTED>;
CLASS variable(s) </ option(s)>;
FREQ variable;
ID variable(s);
OUTPUT <OUT=SAS-data-set> <output-statistic-specification(s)>
<id-group-specification(s)> <maximum-id-specification(s)>
<minimum-id-specification(s)> </ option(s)> ;
TYPES request(s);
VAR variable(s) < / WEIGHT=weight-variable>;
WAYS list;
WEIGHT variable; 
 
主要功:The MEANS procedure provides data summarization tools to compute descriptive statistics for variables across all observations and within groups of observations(計算描述性統計量,比如均值方差等,還可以用來做置性區間的計算) 
 
常用用法:
  • calculates descriptive statistics based on moments 計算基於矩的描述性統計量,如均值、方差、標准差、偏度、峰度
  • estimates quantiles, which includes the median 計算分位數
  • calculates confidence limits for the mean  計算均值的置性區間
  • identifies extreme values 極值
   performs a t test t檢驗
 <option(s)>常用項:
data=<制定輸入的數據集>
(field width)fw=<specifies the field width to display the statistics in printed or displayed output>
maxdec=<specifies the maximum number of decimal places to display the statistics in the printed or displayed output>
missing= <If you omit MISSING, then PROC MEANS excludes the observations with a missing class variable value from the analysis>
noobs noprint
NWAY:specifies that the output data set contain only statistics for the observations with the highest _TYPE_ and _WAY_ values,使輸出數據集中包含_type_和_way_的最大值
 <statistic-keyword(s)>
默認輸出統計量: std標准差、n觀測個數、means均值、min/max
cv 變異系數、 stderr標准誤即樣本均值的方差、 css偏差平方和、vardef自由度,clm雙尾置性區間,LCLM左尾置性區間,UCLM右尾置性區間,
ALPHA=default0.05 (1-置信度)。
 
Types語句:規定輸出結果的分組類型和順序,其中的變量一定要在class語句中,和class語句中變量的順序有關
例如class a b c;則 type () a b a*b c a*c b*c a*b*c的type值分別為0 1 2 3 4 5 6 7,type值決定其輸出順序,不同的t ype類型有些類似tabulate中的table語句,規定以何種變量為分組類型輸出; 
 
by語句:必須先排序才能用by語句,by語句進行的分組在輸出時會輸出兩個表,而class不會
 
var語句:規定需要分析的變量
 
ID語句:取對應變量的最大值放入數據集;
 
output語句:規定輸出數據集以及要輸出的變量
 
proc means data=school maxdec=2 noprint nway; 
/*specifies that the output data set contain only statistics for the observations with the highest _TYPE_ and _WAY_ values*/
    class teacher;
   class gender region; *兩個變量都取0 1兩個值,二進制。00 01 10 11; id t_Age;
*id取對應變量的最大值放入數據集; var pretest posttest gain; output out=teachersum1(drop= _type_ rename=(_freq_ = number)) *刪除變量;
       mean=m_pre m_post m_gain ; *單class 下output數據集的表示;        max =
       min = /autoname; *autoname很重要,可以和自己起名的變量混用;
run;
二進制   _type_ 解釋
0       0   0 總平均數
0       1   1 不同region的平均數
1   0   2 不同gender的平均數
1   1   3 單元格平均數
 
                                    class gender region; *兩個變量都取0 1兩個值,二進制。00 01 10 11;
 

 

/*********************proc freq**********************/

PROC FREQ <options>; (order=freq選項,按freq從高到低排序)

BY variables ;

EXACT statistic-options </ computation-options> ;

OUTPUT <OUT=SAS-data-set> options ;

TABLES requests </ options> ; *列出不同變量間組合的頻數,也可以做相關性分析;

TEST options ;

WEIGHT variable </ option> ; 

tables選項:畫出其中規定要輸出的變量組合的表格
If you omit the TABLES statement, PROC FREQ generates one-way frequency tables for all data set variables that are not listed in the other statements.
例如含有變量num t1 t2的一張表格,如果限定tables t1;則只會對t1畫出相應的頻數表,
但是如果省略table,則會畫出其他變量的頻數表(有一個模糊的條件,這里不一定是畫出全部的??????有待考證)
request中的組合方式  
 
</options中常用選項>更多查看sashelp
1:Create an Output Data Set 
 1.1 out=Names an output data set to contain frequency counts, out只輸出table中最后一個數據集,如果想輸出多個數據集,則需要寫過個table語句
 1.2 outexpect= Includes expected frequencies in the output data set 
2:Control Statistical Analysis
 2.1 nocum 無累加
 2.2 nopercent 無百分比 這兩個對雙向列聯表特別有用
3:Control Additional Table Information
 
/******************proc univariate*******************/
PROC UNIVARIATE <options> ;
BY variables ;
CDFPLOT <variables> < / options> ;
CLASS variable-1 <(v-options)> <variable-2 <(v-options)>> </ KEYLEVEL= value1 | ( value1 value2 )> ;
FREQ variable ;
HISTOGRAM <variables> < / options> ;
ID variables ;
INSET keyword-list </ options> ;
OUTPUT <OUT=SAS-data-set> <keyword1=names ...keywordk=names> <percentile-options> ;
PPPLOT <variables> < / options> ;
PROBPLOT <variables> < / options> ;
QQPLOT <variables> < / options> ;
VAR variables ;
WEIGHT variable ;  
 
主要功能:描述統計量, 畫圖比如QQ PP,還有畫分布函數圖,頻數圖,箱線圖,正態性檢驗等(紅線部分是與means的區別)
/****************************************************
 經驗之談(多個箱線圖一起能很好的了解一個變量不同水平的數據分布的情況)
*****************************************************/
PROC UNIVARIATE <options> ;
options的選項有
normal:進行正態性檢驗 <Shapiro-Wilk檢驗,W檢驗統計量,越接近1越好,拒絕與為w<Wa>;
mu=num1 num2:均值的假設檢驗,后面寫兩個分別對應兩個相應的均值
Nextrobs=num;分別呈現的num個最小值和最大值
 
example!!!!!
proc
univariate data=test normal plot nextrobs=6;
進行正態性檢驗,畫出箱線圖,莖葉圖,設置6個極端值

 

proc univariate data=reg.b_fitness;
    var Runtime -- Performance;
    histogram Runtime -- Performance / normal;  /*主要從統計指標上面看*/
    probplot Runtime -- Performance /normal (mu=est sigma=est color=red w=2);/*主要從圖形來看*/
run;

 

 

PROBPLOT <variables> < / options> :The PROBPLOT statement creates a probability plot, which compares ordered variable values with the percentiles of a specified theoretical distribution(主要用來畫概率圖,也就是 PP圖,option中加入你想要做的擬合分布檢驗的分布名,從概率上檢驗分布)
< / options>:specify the theoretical distribution for the plot or add features to the plot. If you specify more than one variable, the  options apply equally to each variable(具象話理論分布,如果不只一個變量,則對每個變量都適用)You can specify only one  option that names a distribution in each PROBPLOT statement(每個PROBPLOT語句只能有一個分布選項,但是可以有很多其他選項), but you can specify any number of other  options
options中  EST表示極大似然估計得到的值。
 
example!!!!!!!!!!!
proc univariate; probplot Length / normal(mu=10 sigma=0.3 color=red l= w=);*這三個選項對所有分布都適用,對特定分布適用的選項查看sas help!; run;

l=specifies line type of distribution reference line 
w=specifies width of distribution reference line 
color=specifies color of distribution reference line 

 

HISTOGRAM <variables> < / options> ;creates histograms and optionally superimposes estimated parametric and nonparametric probability density curves( 建立直方圖並往上添加曲線,從圖形上檢驗分布)
proc univariate data=Steel;
   histogram Length / normal
                      midpoints = 5.6 5.8 6.0 6.2 6.4
                      ctext     = blue;
run;
生成直方圖,加上正太曲線並制定直方圖的重點,然后設置文本的顏色

 

 

INSET keyword-list </ options> ;places a box or table of summary statistics, called an inset, directly in a graph created with a CDFPLOT, HISTOGRAM, PPPLOT, PROBPLOT, or QQPLOT statement( 往圖表中添加小的,數據描述表格,可以指定位置
PROC UNIVARIATE DATA=HTWT;
   TITLE "More Descriptive Statistics";
   VAR HEIGHT WEIGHT;
   HISTOGRAM HEIGHT / MIDPOINTS=60 TO 75 BY 5  NORMAL;
   INSET MEAN (5.2)  /*不輸入別名會顯示系統自定義的命名,5.2是wd*/
         STD='Standard Deviation' (6.3)/ FONT='Arial' 
                                         POS=NW /*插入小表格的位置*/
                                         HEIGHT=3;
RUN;

 

 
 
 
 
 
 
 
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM