[英]SAS code for multiple entries of primary key and corresponding data
我有如下數據
p_id E_id
---- ----
1 1
1 2
1 3
1 4
2 1
3 1
3 2
3 3
4 1
對於每個primary_id
我必須創建一個對應的E_id
的表。
我該如何在SAS中做到這一點?
我在用:
proc freq data = abc;
where p_id = 1;
tables p_id * E_id;
run;
如何概括所有主鍵的where語句?
by
語句是如何為每個ID獲得單獨的表。 它要求數據按變量排序。
proc freq data = abc;
by p_id;
tables p_id * E_id;
run;
這是一個允許您選擇p_id
生成頻率表的解決方案。
data have;
input p_id e_id;
datalines;
1 1
1 2
1 3
1 4
2 1
3 1
3 2
3 3
4 1
;
run;
proc sort data = have;
by p_id;
run;
%let pid_list = (1,2); ** only generate two tables;
data _null_;
set have;
by p_id;
if first.p_id and p_id in &pid_list then do;
call execute('
proc freq data = have(where = (p_id = '||p_id||'));
tables p_id * e_id;
run;
');
end;
run;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.