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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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