Hello programmers,
I'll appreciate if anyone can give me an insight. I am trying to assign a value to a cluster of individuals.
Each individual have a yes or no response and i want to assign the proportion of yeses to all in the individual in that cluster.
Eg. ID is nested in cluster 104; responses are yeses and nos. value is the proportion of "yeses"= 6/20=0.3. My challenge is how to call this value on every ID in the cluster.
Any help is appreciated.
ID cluster Ab value
1 104 yes 0.3
2 104 no 0.3
3 104 no 0.3
4 104 no 0.3
5 104 no 0.3
6 104 no 0.3
7 104 no 0.3
8 104 yes 0.3
9 104 yes 0.3
10 104 yes 0.3
11 104 yes 0.3
12 104 yes 0.3
13 104 no 0.3
14 104 no 0.3
15 104 no 0.3
16 104 no 0.3
17 104 no 0.3
18 104 no 0.3
19 104 no 0.3
20 104 no 0.3
One solution: proc freq for the calculation and and data step merge to add the variable.
proc freq data=have noprint;
by cluster;
table ab / out=count(where=(Ab ='yes'));
run;
data want;
merge have count(keep= cluster percent rename=(percent = value));
by cluster;
if first.cluster then value = value / 100;
run;
One solution: proc freq for the calculation and and data step merge to add the variable.
proc freq data=have noprint;
by cluster;
table ab / out=count(where=(Ab ='yes'));
run;
data want;
merge have count(keep= cluster percent rename=(percent = value));
by cluster;
if first.cluster then value = value / 100;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.