proc - Two Way Transpose SAS Table -


i trying create 2 way transposed table. original table have looks like

id      cc 1       2 1       5 1       40 2       55 2       2 2       130 2       177 3       20 3       55 3       40 4       30 4       100

i trying create table looks like

cc        cc1     cc2…  …cc177 1         264     5        0 2         0      132       6 … … 177       2        1      692

in other words, how many id have cc1 have cc2..cc177..etc

the number under id not count; id range 3 digits 5 digits id or numbers such 122345ab78

is possible have percentage display next each other?

    cc        cc1 %    cc2    %…  …cc177 1          264 100%   5 1.9%        0 2           0         132           6 … … 177         2              1       692 

if want change cc1 cc2 characters, how modify arrays? eventually, table looks like

cc     dell lenovo hp sony dell lenovo hp sony 

the order of names must match cc number provided above. cc1=dell cc2=lenovo, etc. want add percentage matrice. if dell x dell = 100 , dell x lenovo = 25, dell x lenovo = 25%.

this changes data structure wide format indicator each value of cc , uses proc corr (correlation) create summary table.

proc corr generate sccp - uncorrected sum of squares , crossproducts. it's that's related correlation, gist creates table you're looking for. table output in sas results window , ods output statement capture table in dataset called coocs.

data temp; set have; id; retain cc1-cc177; array cc_list(177) cc1-cc177;  if first.id i=1 177;    cc_list(i)=0; end;  cc_list(cc)=1;  if last.id output;  run;   ods output sscp=coocs; ods select sscp; proc corr data=temp sscp; var cc1-cc177; run; proc print data=coocs; run; 

here's answer, it's inefficient , has it's issues. one, if value not anywhere in list not show in results, i.e. if there no 20 in dataset there no 20 in final data. also, variables out of order in final dataset.

proc sql; create table bigger select a.id, catt("cc", a.cc) cc1, catt("cc", b.cc) cc2 have cross join have b a.id=b.id; quit;  proc freq data=bigger noprint; table cc1*cc2/ list out=bigger2; run;  proc transpose data=bigger2 out=want2; cc1; var count; id cc2; run; 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -