我想在沒有proc sql的情況下在數據步驟中執行相同的操作。 注:變量1可變不同變量的SAS計數 - 數據步驟
proc sql;
select count(distinct(variable1)),variable2,varibale3
from tablename group by variable2,variable3;
quit;
TIA
我想在沒有proc sql的情況下在數據步驟中執行相同的操作。 注:變量1可變不同變量的SAS計數 - 數據步驟
proc sql;
select count(distinct(variable1)),variable2,varibale3
from tablename group by variable2,variable3;
quit;
TIA
一個字符,該解決方案是基於你其實是想你的結果,而無需使用PROC SQL的假設。
打破在不同的步驟解決方案以保持它非常簡單,容易爲你understand.:-
/*Step 1 This step just keeps the required variables in the dataset*/
data tablename(keep=variable1 variable2 variable3);
set tablename;
run;
/*Step 2 Sorting and using noduprecs to keep distinct records in the table*/
Proc sort data=tablename nodupkey;
by _all_;
run;
/*Step 3 Creating a tag as 1, so as to enable us to sum or count the distinct values*/
Data tablename;
set tablename;
tag=1;
run;
/*Step 4 Using Proc means to sum the tag inside var on the combination of Variable1 and Variable3 which is inside the Class*/
/*I have used PROC MEANS here. You can do the same thing using PROC TABULATE or PROC REPORT*/
proc means data=tablename sum;
class variable2 variable3;
var tag;
run;
讓我知道,如果你還有任何疑問
我對數據集進行了排序,但沒有使用nodupkey選項,因此它現在沒有給出結果,其工作正常 – rocky
@rocky如果此解決方案對您有所幫助,請訪問此鏈接http://stackoverflow.com/help/someone-answers –
我不會用數據步,使用雙處理器頻率。在PROC FREQ
proc freq data=have noprint;
table variable2*variable3*variable1 /out= first_summary;
run;
proc freq data=first_summary noprint;
table variable2*variable3/out=want;
run;
proc print data=want;
run;
我認爲你的第二張表應該是'variable2 * variable3'? – Joe
NLEVELS
選項是讓這個最簡單的方法。假設它是按變量2 /變量3排序的,這很簡單。這是一個使用sashelp.class
的例子;這裏sex
代表變量2和變量3,而age
代表計數變量。
proc sort data=sashelp.class out=class;
by sex;
run;
ods output nlevels=levels_age_sex; *nlevels table is output;
proc freq data=class nlevels; *nlevels here asked for output;
by sex; *grouping variable;
tables age/noprint; *do not actually want table;
run;
ods output close; *technically unnecessary but I like symmetry;
爲什麼數據步驟而不是PROC步驟? – Joe