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;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 816 views
  • 0 likes
  • 2 in conversation