- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-09-2020 05:20 PM
(967 views)
not sure why I'm having so much trouble with this. I'm trying to create a sum column based on a output _freq_ column from proc summary. I ultimately want to make a percent from the freqs like so, where var, _TYPE_ and _FREQ_ are from my output out statement:
var | _TYPE_ | _FREQ_ | want | want2 |
a | 1 | 10 | 138 | 0.072464 |
b | 1 | 23 | 138 | 0.166667 |
c | 1 | 21 | 138 | 0.152174 |
d | 1 | 34 | 138 | 0.246377 |
e | 1 | 50 | 138 | 0.362319 |
f | 1 | 0 | 138 | 0 |
I can't get want and want2.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @richart It appears you wanna group by _type_
proc sql;
create table want as
select * ,sum(_freq_) as want, _freq_/calculated want as want2 format=8.2
from have
group by _type_
order by _type_ ,var;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Since VAR is character, this is a very simple job for PROC FREQ.
proc freq data=have;
tables var/noprint out=counts;
run;
If you really want a column called WANT with 138 on every row, this would require another step. But PROC FREQ gives the count for each level of VAR and the percent.
--
Paige Miller
Paige Miller