How to do complex(ish) calculations with variable frequencies/percentages?

Reply
New Contributor
Posts: 2

How to do complex(ish) calculations with variable frequencies/percentages?

Hello,

I have a dataset that gives scores for each individual:

IDCat1Cat 2
2224511
5451551
5451534

I need two different levels of data from these scores:1, the frequencies of each (for cat1 and cat2), 1-5, which I easily get with Proc Freq, and 2) a calculated summary scores using the following equation and a variation (one for each of cat1 and cat2): (3+4)/(1+2+3+4)

1140.33140.33
2105725.08107125.42
351112.13158237.54
485920.38244157.93
5177342.074214100.00

If I export my Proc Freq then I have a nice dataset that looks like the above table, but I don't know how to get this into another dataset or table that calculates my final score.

Thoughts?

Super User
Posts: 19,822

Re: How to do complex(ish) calculations with variable frequencies/percentages?

Where is the 1+2+3+4 coming from?

New Contributor
Posts: 2

Re: How to do complex(ish) calculations with variable frequencies/percentages?

Those are the observation numbers. The calculation will look like this, filling in the frequencies for the observation numbers:

(511+859)/(14+1057+511+859) = 1370/2441 = 0.5612

Is there a way to automate that calculation so that I can export it and any other calculations into another dataset?

Super User
Posts: 19,822

Re: How to do complex(ish) calculations with variable frequencies/percentages?

I can't be 100% sure because you have two sets of sample data that don't match up and that's confusing me.

I think you may want to look into the multi label format and proc tabulate which will calculate these for you automatically.

This is under the assumption you want a standard proc freq, but then some pre defined categories as well,

For example, your data has values 1, 2, 3,4 and you want to count how many 1, 2, 3, 4 and 3/4 together.

Super User
Posts: 10,035

Re: How to do complex(ish) calculations with variable frequencies/percentages?

data have;
input a b c d e;
cards;
1     14     0.33     14     0.33
2     1057     25.08     1071     25.42
3     511     12.13     1582     37.54
4     859     20.38     2441     57.93
5     1773     42.07     4214     100.00
;
run;
data var(keep=var1 var2);
 set have ;
 array x{4} _temporary_;
 array y{4} _temporary_;
 x{_n_}=b; y{_n_}=d;
 if _n_ eq 4 then do;
   var1=(x{3}+x{4})/sum(of x{*}) ;
   var2=(y{3}+y{4})/sum(of y{*}) ;
  output; stop;
 end;
run;


Xia Keshan

Ask a Question
Discussion stats
  • 4 replies
  • 219 views
  • 0 likes
  • 3 in conversation