Sunday, 15 June 2014

How to show variable value by proc tabulate in sas? -



How to show variable value by proc tabulate in sas? -

how can manage proc tabulate show value of variable missing value instead of statistic? thanks!

for example, want show value of sym. takes value 'x' or missing value. how can it?

sample code:

data test; input tx mod bm $ yr sym $; datalines; 1 1 0 x 1 2 0 x 1 3 0 x 2 1 0 x 2 2 0 x 2 3 0 x 3 1 0 3 2 0 3 3 0 x 1 1 b 0 x 1 2 b 0 1 3 b 0 1 4 b 0 1 5 b 0 2 1 b 0 2 2 b 0 2 3 b 0 2 4 b 0 2 5 b 0 3 1 b 0 x 3 2 b 0 3 3 b 0 1 1 c 0 1 2 c 0 x 1 3 c 0 2 1 c 0 2 2 c 0 2 3 c 0 3 1 c 0 3 2 c 0 3 3 c 0 1 3 1 x 2 3 1 3 3 1 1 3 b 1 2 3 b 1 3 3 b 1 1 3 c 1 x 2 3 c 1 3 3 c 1 ; run; proc tabulate data=test; class yr bm tx mod ; var sym; table yr*bm, tx*mod; run;

proc tabulate data=test; class tx mod bm yr sym; table yr*bm, tx*mod*sym*n; run;

that gives ones each sym=x (since n=missing). hides rows sym=missing, hence miss values overall illustration table. (you format column format defines 1 = 'x' easily).

proc tabulate data=test; class tx mod bm yr; class sym /missing; table yr*bm, tx*mod*sym=' '*n; run;

that gives of combinations of 4 main variables, includes missing syms own column.

if want have cake , eat too, need redefine sym numeric variable, can utilize var.

proc format; invalue isym x=1 ; value fsym 1='x'; quit; info test; infile datalines truncover; input tx mod bm $ yr sym :isym.; format sym fsym.; datalines; 1 1 0 x 1 2 0 x 1 3 0 x ... more lines ... ; run; proc tabulate data=test; class tx mod bm yr; var sym; table yr*bm, tx*mod*sym*sum*f=fsym.; run;

all of these assume these unique combination rows. if start having multiples of yr*bm*tx*mod, have problem here wouldn't give expected result (sum 1+1+1=3 not give 'x').

sas

No comments:

Post a Comment