2012-01-26 2 views
1

proc 리포트를 얻는 데 어려움을 겪고 있습니다.PROC REPORT 및 요약 라인과의 레슬링

상태, 항목, 개수, 주별 백분율 및 전체 백분율을 가진 테이블이 있습니다. 총계와 주 총계를 요약하는 줄이 있습니다. 내 문제는 그 요약 라인이 전체 합계 수준에서 주 합계를 요약한다는 것입니다. 과 같이 :

CODE :

proc report data=dataset nowd ; 
columns state item count pct_state percent; 

define state /order 'State'; 
define item/'Status'; 
define count/'#'; 
define pct_state/'% of State'; 
define percent/'% of Total'; 

break after state/ol summarize; 
compute after state; 
    item=catt(state,' Total'); 
    state = ''; 
    line @1 ' '; 
endcomp; 
rbreak after /ol summarize; 
compute after; 
    involved = 'Grand Total'; 
endcomp; 
run; 

테이블과 같이 만든다 :

State Item # %state %total 
AL  A  2 40.0% 20.0% 
     B  3 60.0% 30.0% 
    AL Total 5 100.0% 50.0% 

MN  A  1 20.0% 10.0% 
     B  1 20.0% 10.0% 
     C  3 60.0% 30.0% 
    MN Total 5 100.0% 50.0% 

Grand Total 10 200.0% 100.0% 

당신이 볼 수 있듯이, 그것은 터무니없는 수의 200 %의 상태 %의 전체를보고합니다. 나는 그것이 국가 가치를 전혀 요약하지 않는 것을 선호 할 것이다. SAS가 수치 변수로 해석하여 요약하기 때문에 요약 라인이있는 테이블에서 날짜를 사용하는 것에 대해 sas 웹 사이트에서 경고합니다. 그러나 좋은 해결책은 아닙니다. BREAKRBREAK 문에 지정할 수있는 "VAR"옵션이없는 이유를 이해할 수 없지만 해결 방법이 필요합니다.

필자가 생각해 본 것은 새로운 변수를 만들고 텍스트로 백분율을 저장하여 요약에서 계산할 수 없도록하는 것이지만 실제로는이를 수행하는 거꾸로입니다.

data dataset; set dataset; 
    state_txt = trim(left(put(pct_state,percent10.1))); 
run; 

proc report data=dataset nowd ; 
columns state item count state_txt percent; 

define state /order 'State'; 
define item/'Status'; 
define count/'#'; 
define state_txt/right '% of State'; 
define percent/'% of Total'; 

break after state/ol summarize; 
compute after state; 
    item=catt(state,' Total'); 
    state = ''; 
    line @1 ' '; 
endcomp; 
rbreak after /ol summarize; 
compute after; 
    involved = 'Grand Total'; 
endcomp; 
run; 

(이 문자 변수이기 때문에) 이것은 요약을 모두 제거하지만 내가 rbreak after /summarize var=count percent; 같은 것을 말과 함께 할 수 있어야 일을 단지 끔찍한 방법처럼 보인다. 더 좋은 방법이 있습니까? 또한, 국가 별 레벨을 100 %로 요약해도 괜찮습니까? 우선 순위가 아니며 바닥에 200 %를 말하지 않는 것보다 중요하지 않습니다 (또는 전체 미국 표, 5000 %).

샘플 데이터 :

data dataset; 
length state item $50; 
infile datalines delimiter=','; 
input state item $ count percent pct_state; 
datalines; 
    AL,A,8,0.0047,1.0000 
    DC,A,1,0.0006,0.5000 
    DC,B,1,0.0006,0.5000 
    FL,A,18,0.0107,0.7500 
    FL,B,2,0.0012,0.0833 
    FL,C,4,0.0024,0.1667 
    LA,A,434,0.2576,0.8314 
    LA,B,69,0.0409,0.1322 
    LA,C,19,0.0113,0.0364 
    MI,A,1,0.0006,1.0000 
    MS,A,4,0.0024,0.8000 
    MS,B,1,0.0006,0.2000 
    OK,A,2,0.0012,1.0000 
    PA,A,1,0.0006,1.0000 
    TX,A,943,0.5596,0.8435 
    TX,B,132,0.0783,0.1181 
    TX,C,43,0.0255,0.0385 
    VA,A,1,0.0006,1.0000 
    WI,B,1,0.0006,1.0000 
    ; 
+0

하는 일부를 게시 할 수 (도움이 될 수있는, 왼쪽 아웃 = 문에서)

을 : (이 데이터를 나타내지 않는 경우 알려주세요, 내가 slighty를 데이터를 변경)이 시도 샘플 데이터? 보고서 코드로 작업하는 것이 더 쉬워집니다 ... –

+0

샘플 데이터 추가 - 백분율을 소수점 이하 4 자리로 반올림함에 따라 백분율이 최대 100 개까지 추가되지 않을 수 있습니다. – orh

답변

2

내가 AFTER 트릭을 할 것입니다 일부 컴퓨의 논리 경우를 사용하여 생각합니다.

data dataset; 
length state item $50; 
infile datalines delimiter=','; 
input state item $ count percent pct_state; 
format percent pct_state percent10.1; 
datalines; 
    AL,A,8,0.8,1.0000 
    DC,A,1,0.1,0.5000 
    DC,B,1,0.1,0.5000 
; 

proc report data=dataset nowd out=work.report; 
columns state item count pct_state percent; 

    define state /order 'State'; 
    define item/'Status'; 
    define count/'#'; 
    define pct_state/'% of State'; 
    define percent/'% of Total'; 

    break after state/ol summarize; 
    compute after state; 
    item=catt(state,' Total'); 
    state = ''; 
    line @1 ' '; 
    endcomp; 

    rbreak after /ol summarize; 
    compute after; 
    State = 'Grand Total'; 
    if pct_state.sum>1 then pct_state.sum=1; 
    endcomp; 

run; 
+0

감사합니다. 필자는 rbreak의 계산 블록에서'pct_state.sum = '''이라고 말하면서 (그리고 per-state 계산에서도 마찬가지다) 좀 더 바꿀 것이라고 생각합니다. 전에 pct_state = ''로이 작업을 시도했습니다. 그리고 그것은 작동하지 않았다 - 나는 ".sum" – orh