Hi all,
I have a question about using an output result for IF statement.
For example, I have a following data about size of a product.
My plan is to:
As I have 32 products, I would like to know if it can be done in a loop or something. Thanks in advance.
Best,
David
Have
Size |
0.5 |
0.5 |
1 |
1 |
1 |
2 |
1 |
1 |
1 |
2 |
1 |
1 |
1 |
1 |
1 |
Want
Size | Group |
0.5 | 1 |
0.5 | 1 |
1 | 2 |
1 | 2 |
1 | 2 |
2 | 3 |
1 | 2 |
1 | 2 |
1 | 2 |
2 | 3 |
1 | 2 |
1 | 2 |
1 | 2 |
1 | 2 |
1 | 2 |
Use PROC RANK with GROUPS=4. This will place each value into one of 4 groups by quartiles, numbered as 0 through 3. If you want to have the group 25 percentile to 75 percentile, you can combine groups 1 and 2 from PROC RANK. No looping is needed, PROC RANK supports the use of a BY statement, so you can run PROC RANK once on all 32 products.
Example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p12aek9f6xhl1zn1puuuot19wqi7.htm
Use PROC RANK with GROUPS=4. This will place each value into one of 4 groups by quartiles, numbered as 0 through 3. If you want to have the group 25 percentile to 75 percentile, you can combine groups 1 and 2 from PROC RANK. No looping is needed, PROC RANK supports the use of a BY statement, so you can run PROC RANK once on all 32 products.
Example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p12aek9f6xhl1zn1puuuot19wqi7.htm
Thanks 🙂 It works.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.