Hello Everyone , I have this Dataset :
| User | Orders | Fam | Num_Fam |
| 2563 | 1542 | 66 | 1 |
| 2563 | 2251 | 66 | 1 |
| 2563 | 1544 | 66 | 1 |
| 2563 | 2222 | 28 | 1 |
| 2563 | 2335 | 28 | 1 |
And i want to get the percentage for each user , the percentage of each fam , that is , since in my case the fam 68 is repeated 3 times i want to get next to each row 33.33% , for the fam 28 since it is repeated 2 times i want to get 50% for each row , so the output would be like this :
| User | Orders | Fam | Num_Fam | per |
| 2563 | 1542 | 66 | 1 | 33,33% |
| 2563 | 2251 | 66 | 1 | 33,33% |
| 2563 | 1544 | 66 | 1 | 33,33% |
| 2563 | 2222 | 28 | 1 | 50% |
| 2563 | 2335 | 28 | 1 | 50% |
| 2563 | 5455 | 20 | 1 | 100% |
Any Help Would Be Much Appreciated , Thank you .
One way
data have;
input User Orders Fam Num_Fam;
datalines;
2563 1542 66 1
2563 2251 66 1
2563 1544 66 1
2563 2222 28 1
2563 2335 28 1
;
proc sql;
create table want as
select *, 1/(count(Fam)) as per format=percent8.2
from have
group by Fam;
quit;
One way
data have;
input User Orders Fam Num_Fam;
datalines;
2563 1542 66 1
2563 2251 66 1
2563 1544 66 1
2563 2222 28 1
2563 2335 28 1
;
proc sql;
create table want as
select *, 1/(count(Fam)) as per format=percent8.2
from have
group by Fam;
quit;
Alternatively
data want;
do _N_=1 by 1 until (last.Fam);
set have;
by Fam notsorted;
end;
do until (last.Fam);
set have;
by Fam notsorted;
per=1/_N_;
output;
end;
format per percent8.2;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.