2017-05-09 6 views
0

proc freq를 사용하지 않고이 한 열 데이터의 도수 분포를 수행해야합니다. proc sql. proc sort 만 사용할 수 있습니다.proc을 사용하지 않고 SAS countif 기능

Excel에서 나는 간단한 countif를 사용할 것이지만, 위의 조건에 따라 SAS에서 이것을 수행하는 방법을 모르겠습니다.

data sample_grades; 
input grades $; 
datalines; 
C 
A 
A 
B 
B+ 
A- 
W 
A 
A- 
A 
A- 
A 
B+ 
A- 
A 
B+ 
B+ 
A- 
B+ 
; 
run; 

나는이 함께했다하지만 나는이 같은 간단한 테이블을 찾고 궁극적으로 A-

data new_dataset; 
set Fall2016; 
by grade; 
retain grade frequency; 
if grade = 'A' then frequency+1; 
else if grade = 'A-' then frequency=0; 
if grade = 'A-' then frequency+1; 
else if grade = 'B' then frequency=0; 
if grade = 'B' then frequency+1; 
else if grade = 'B+' then frequency=0; 
if grade = 'B+' then frequency+1; 
else if grade = 'B-' then frequency=0; 
if grade = 'B-' then frequency+1; 
else if grade = 'C' then frequency=0; 
if grade = 'C' then frequency+1; 
else if grade = 'W' then frequency=0; 
if grade = 'W' then frequency+1; 
else frequency+0; 
if last.grade then do; 
frequency+0; 
end; 
run; 

에서 계산 중지 : enter image description here

답변

1

그것은 데이터를 생각하는 데 도움이 루프로 단계, 입력 데이터 세트를 실행하고 값을 가져옵니다. 나는 당신의 시도가 그 점에서 어떻게 작용했는지를 설명하려고했지만, 빨리 혼란스러워졌습니다. 이제 다음과 같이 데이터 단계를 설정

proc sort data=sample_grades; 
    by grades; 
run; 

: BY-GROUP 처리가 이루어질 수 있도록

data sample_grades; 
input grades $; 
datalines; 
C 
A 
A 
B 
B+ 
A- 
W 
A 
A- 
A 
A- 
A 
B+ 
A- 
A 
B+ 
B+ 
A- 
B+ 
; 
run; 

분류, 등급에 의한 데이터 첫째 : 여기에 문제의 내 시도이다

data new_dataset; 
    set sample_grades; 
    by grades; 
    /* If it's the first of the grades then set the frequency to zero */ 
    if first.grades then frequency=0; 
    /* Increment the frequency value regardless of the value of grades */ 
    frequency+1; 
    /* When the last of the grades values is found, output. This gives the total frequency for the grade in the output table */ 
    if last.grades then output; 
run;