Hi,
I woud like to know if there is a way of grouping automatically a variable. I have the table below, customer_id and Total_plays. I would like to group the Total_plays automatically. I usually use proc univariate , then group it manuallly myself.
Is there any way to do it automatically, without using manual process.
Your help would be much appreciated.
Thank you
Have
|
Customer_id |
Total_plays |
|
100000 |
1 |
|
110000 |
3 |
|
120000 |
1 |
|
130000 |
5 |
|
140000 |
1 |
|
150000 |
2 |
|
160000 |
1 |
|
170000 |
1 |
|
180000 |
1 |
|
190000 |
4 |
|
200000 |
4 |
|
210000 |
3 |
|
220000 |
1 |
|
230000 |
37 |
Want
|
Customer_id |
Total_plays |
|
100000 |
1 |
|
110000 |
3 to 5 |
|
120000 |
1 |
|
130000 |
3 to 5 |
|
140000 |
1 |
|
150000 |
2 |
|
160000 |
1 |
|
170000 |
1 |
|
180000 |
1 |
|
190000 |
3 to 5 |
|
200000 |
3 to 5 |
|
210000 |
3 to 5 |
|
220000 |
1 |
|
230000 |
> 5 |
Try the format
proc format fmtlib;
value cat
low-1='1'
2='2'
3-5='3-5'
6-high='>5';
run;
data have;
input Customer_id Total_plays;
format Total_plays cat.;
cards;
100000 1
110000 3
120000 1
130000 5
140000 1
150000 2
160000 1
170000 1
180000 1
190000 4
200000 4
210000 3
220000 1
230000 37
;
You want to group N observations for variable X into G groups, based upon the value of X. How about proc rank?
Let's say you want 4 groups, and you want those groups to be as equal in size as possible. Then:
proc rank data=have out=want group=4;
var x;
ranks xgroup;
run;
This will produce new variable Xgroup=0,1,2, or 3. Note that all tied values of X are assigned to the same group, so in the presence of ties, groups need not be the same size.
Don't understand you question.
What is the rule to group this variable ?
data have;
input Customer_id Total_plays;
format Total_plays cat.;
cards;
100000 1
110000 3
120000 1
130000 5
140000 1
150000 2
160000 1
170000 1
180000 1
190000 4
200000 4
210000 3
220000 1
230000 37
;
proc rank data=have group=5 ties=dense out=want;
var Total_plays;
ranks rank;
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.