SASテクニック 存在しない水準も含めた要約統計量のデータ作成 classdata/SQL
SASによる存在しない水準も含めた要約統計量のデータ作成
SASHELP.CLASSで、年齢/性別ごとに集計する
16歳は、男性のみのデータとなっている
年齢/性別のデータ作成(meansプロシジャで利用)
proc Sql;
create table work.CD as
select A.AGE , B.SEX
from ( select distinct AGE from sashelp.CLASS ) as A
cross join ( select distinct SEX from sashelp.CLASS ) as B
order by A.AGE , B.SEX;
quit;
proc Sql;
create table work.CD as
select A.AGE , B.SEX
from ( select distinct AGE from sashelp.CLASS ) as A
cross join ( select distinct SEX from sashelp.CLASS ) as B
order by A.AGE , B.SEX;
quit;
classdataの指定せず、シンプルに集計
%* classdataなし *;
proc Means data = sashelp.CLASS nway noprint;
class AGE SEX;
var HEIGHT;
output out = work.STAT0 n = N mean = MEAN;
run;
%* classdataなし *;
proc Means data = sashelp.CLASS nway noprint;
class AGE SEX;
var HEIGHT;
output out = work.STAT0 n = N mean = MEAN;
run;
16歳女性のレコードは作成されない
classdataを指定して16歳女性のレコードを作る場合
%* classdataあり *;
proc Means data = sashelp.CLASS classdata = work.CD nway noprint;
class AGE SEX;
var HEIGHT;
output out = work.STAT1 n = N mean = MEAN;
run;
集計結果とダミーデータをmergeすることで16歳女性のレコードを作る場合
%* sqlで *;
proc Sql;
create table work.STAT2 as
select A.* , coalesce( B.N , 0 ) as N , B.MEAN
from
( select *
from ( select distinct AGE from sashelp.CLASS )
cross join ( select distinct SEX from sashelp.CLASS )
) as A
left join
( select AGE , SEX , count(*) as N , mean( HEIGHT ) as MEAN
from sashelp.CLASS
group by AGE , SEX
) as B
on A.AGE = B.AGE and A.SEX = B.SEX
order by A.AGE , A.SEX
;
quit;
%* classdataあり *;
proc Means data = sashelp.CLASS classdata = work.CD nway noprint;
class AGE SEX;
var HEIGHT;
output out = work.STAT1 n = N mean = MEAN;
run;
%* sqlで *;
proc Sql;
create table work.STAT2 as
select A.* , coalesce( B.N , 0 ) as N , B.MEAN
from
( select *
from ( select distinct AGE from sashelp.CLASS )
cross join ( select distinct SEX from sashelp.CLASS )
) as A
left join
( select AGE , SEX , count(*) as N , mean( HEIGHT ) as MEAN
from sashelp.CLASS
group by AGE , SEX
) as B
on A.AGE = B.AGE and A.SEX = B.SEX
order by A.AGE , A.SEX
;
quit;
16歳女性のレコードも含まれる(N=0,MEAN=欠損)
Author And Source
この問題について(SASテクニック 存在しない水準も含めた要約統計量のデータ作成 classdata/SQL), 我々は、より多くの情報をここで見つけました https://qiita.com/saspy/items/655d56ea89e0d239f8c6著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .