Hi:
It would be easier to do what you want if your data were in a different structure. something like this:
[pre]
group id varname varval
group1 A var1 no
group1 A var2 yes
group1 A var3 yes
group1 A var4 no
group2 A var1 yes
group2 A var2 no
group2 A var3 yes
group2 A var4 yes
group1 B var1
group1 B var2 yes
group1 B var3 yes
group1 B var4 no
group2 B var1 yes
group2 B var2
group2 B var3 yes
group2 B var4 no
group1 C var1 no
group1 C var2 no
group1 C var3
group1 C var4 no
group2 C var1 yes
group2 C var2 no
group2 C var3 yes
group2 C var4
[/pre]
(Note that this fake data also has an ID variable, which your data may or may not have.)
Once the data are in this structure, you could use a PROC TABULATE like this:
[pre]
ods listing close;
ods html file='newgrp.html' style=sasweb;
options missing = 0;
proc tabulate data=newgrp f=comma7.;
title '4) Using VARNAME and VARVAL';
class group varname varval / missing;
table varname=' ' all,
group=' '*varval=' ' all;
keylabel n=' ';
run;
ods html close;
[/pre]
So, how do you get from your current structure to the new structure? I'd use either a data step program and array processing or proc transpose. I think the data step approach is probably simpler to understand. That transformation and the entire program is shown below.
cynthia
[pre]
data testgrp;
infile datalines dlm='-';
input group $ var1 $ var2 $ var3 $ var4 $ id $;
return;
datalines;
group1--no--yes--yes--no--A
group2--yes--no--yes--yes--A
group1--.--yes--yes--no--B
group2--yes--.--yes--no--B
group1--no--no--.--no--C
group2--yes--no--yes--.--C
;
run;
options nocenter;
ods listing;
proc print data=testgrp;
title 'current structure';
run;
data newgrp;
set testgrp;
array vn $3 var1-var4;
do i = 1 to 4 by 1;
varname = cat('var',put(i,1.0));
varval = vn(i);
output;
end;
drop var1-var4 i;
run;
proc print data=newgrp noobs;
title 'new structure';
run;
ods listing close;
ods html file='newgrp.html' style=sasweb;
options missing = 0;
proc tabulate data=newgrp f=comma7.;
title '4) Using VARNAME and VARVAL';
class group varname varval / missing;
table varname=' ' all,
group=' '*varval=' ' all;
keylabel n=' ';
run;
ods html close;
[/pre]
... View more