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

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:

  1. Use PROC Univariate to obtain the quartiles.
  2. Categorise the data into three, based on results from Step 1.
    • Group 1 if it's below Q1 (25th percentile)
    • Group 2 if it's within Q1 and Q3
    • Group 3 if it's above Q3
  3. Repeat for different products

 

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
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
DavidLie
Obsidian | Level 7

Thanks 🙂 It works.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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