BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Midi
Obsidian | Level 7

Hello Everyone , I have this Dataset :

 

UserOrdersFamNum_Fam
25631542661
25632251661
25631544661
25632222281
25632335281

 

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 :

 

UserOrdersFamNum_Famper
2563154266133,33%
2563225166133,33%
2563154466133,33%
2563222228150%
2563233528150%
25635455201100%

 

Any Help Would Be Much Appreciated , Thank you .

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
PeterClemmensen
Tourmaline | Level 20

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;

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
  • 2 replies
  • 381 views
  • 0 likes
  • 2 in conversation