Hello,
I have a dataset that gives scores for each individual:
ID | Cat1 | Cat 2 |
---|---|---|
22245 | 1 | 1 |
54515 | 5 | 1 |
54515 | 3 | 4 |
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)
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 |
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?
Where is the 1+2+3+4 coming from?
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?
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.
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.