2015-04-06 129 views
0

我有大學生的縱向數據集,其中包含各種與人口統計和績效相關的信息。我對研究登記狀態感興趣,但該數據集不包含「未登記」的信息(即如果學生離開了一個學期,然後返回)。我需要一種方法來創建一個觀察這個「未註冊」的時間段。數據集的結構如下:創建缺少的觀察

Student_ID Enrollement_Status Year Semester Variable1 Varible2  
    1     1   2011  1   
    1     2   2011  2 
    1     1   2012  2 
    2     2   2011  1 
    2     2   2011  2 

我需要student_id數據1的觀察,用(/ 1和兩個indicatate部分時間滿時間)的0 Enrollement_Status,在年份= 2012的學期= 1。這一年是根據學年(而不是日曆年)計算的,所以對於秋季/春季來說都是一樣的。我還需要複製Variable1 - Variablen的信息,因爲它不會及時更改。可能有一個時間超過一個學期,所以在這種情況下,我需要兩個(或更多)觀察每學期沒有註冊的學生。

謝謝! Brian

+0

請問您有在這裏發帖之前在此的嘗試嗎?有一些問題涉及類似的概念。例如,[This one](http://stackoverflow.com/questions/25646976/creating-all-possible-combinations-in-a-table-using-sas/25647910#25647910)。 [This one also](http://stackoverflow.com/questions/19422954/extend-observations-for-all-years-in-sequence/19429677#19429677)。你確切的問題可能需要一些小的修改,但概念在那裏。 – Joe 2015-04-06 16:38:11

回答

1

您可以使用proc sql來做到這一點。這個想法是生成所有你想要的行 - 這將是所有學生和所有年/學期組合。使用left join來引入現有信息。無以倫比列將NULL

select s.student_id, coalesce(ss.Enrollement_Status) as Enrollement_Status, 
     ys.year, ys.semester, s.variable1, s.variable2 
from (select distinct year, semester from students) ys cross join 
    (select distinct student_id from students) s left join 
    students ss 
    on ss.year = ys.year and ss.semester = ys.semester and 
     ss.student_id = s.student_id; 
0
Data STUDENTS; 
    Input Student_ID Enrollment_Status Year Semester; 
    Datalines; 
1 1 2011 1 
1 2 2011 2 
1 1 2012 2 
2 2 2011 1 
2 2 2011 2 
; 
Run; 

瞭解了SPARSE(PAPER)從@喬的評論。它似乎在做所有可能的學期創建數據集的訣竅。

proc freq data=STUDENTS noprint; 
tables student_id*year*semester/sparse out=all(drop=percent count); 
run; 

然後只要加入兩個數據集來填補空白。不是那樣棘手,@ GordonLinoff的回答,所以如果我錯過了一些東西,我一直有興趣瞭解更多關於SQL

Proc Sql; 
Create table WANT as 
select a.student_id 
, CASE 
     When s.Enrollment_Status=. THEN 0 
     ELSE s.Enrollment_Status 
     END as Enrollment_Status 
, a.year, a.semester 
from all a left join students s on a.student_id=s.student_id and a.year=s.year and a.semester=s.semester 
; 
Quit; 
+0

謝謝! Proc SQL對此非常有用。我想我需要使用數據步驟。欣賞反饋。 – 2015-04-07 01:54:22