BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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;

View solution in original post

1 REPLY 1
andreas_lds
Jade | Level 19

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 340 views
  • 0 likes
  • 2 in conversation