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

I have a dataset with about 100 groups, and I need a histogram of "Number of Cycles" for each group; however, I only want to display values of "Number of Cycles" that are greater than Q3. Is there a convenient way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Please show an example of your data and the code you have so far.  By Q3, do you mean third quartile / 75th percentile?  If so, then you could calculate the 75th percentile  (by group) using PROC MEANS or whatever and merge it onto your data (by group), then use a where statement Where Var>Var_Q3.  But that's just a wild guess, without seeing sample data.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Reeza
Super User
You can add a WHERE statement/clause to your procedure to filter out the data. How exactly the statement/clause structured depends on your data.
If it's a SAS date for example it could be the following since 4 is the only quarter greater than 3.

where qtr(date) = 4;

JonKetchup
Obsidian | Level 7

Appreciate the help. My variable of interest is not a date; it takes on values from 0 to 1500. Also the Q3 will be different for each group, and I believe a where statement will apply universally to all groups.

Reeza
Super User
Please provide an example of your data/use case if you need specific coding help. With what you've provided here we can only suggest an approach, as already done.
JonKetchup
Obsidian | Level 7

Here is an example of the data structure. Each group could have as many as 1000 different values of "Number of Cycles", so each group will have a different Q3. Thus, I am looking to create a separate graph for each group, but the histogram will only display values that are greater than Q3 for that particular group. I apologize if my original question was to ambiguous. 

GroupNumber of Cycles
Group 11
Group 19
Group 12
Group 11
Group 110
Group 15
Group 21
Group 22
Group 23
Group 245
Group 32
Group 35
Group 36
Group 34
Group 35
Group 33
Quentin
Super User

Please show an example of your data and the code you have so far.  By Q3, do you mean third quartile / 75th percentile?  If so, then you could calculate the 75th percentile  (by group) using PROC MEANS or whatever and merge it onto your data (by group), then use a where statement Where Var>Var_Q3.  But that's just a wild guess, without seeing sample data.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Rick_SAS
SAS Super FREQ

Use PROC MEANS to get the values of the Q3 in each group. They merge the Q3 values with the data and output only the values that exceed Q3:

 

data Have;
input Group	N;
datalines;
1	1
1	9
1	2
1	1
1	10
1	5
2	1
2	2
2	3
2  3
2  4
2  6
2  20
2	45
3	2
3	5
3	6
3	4
3	5
3	3
;

proc means data=Have noprint;
by Group;
var N;
output out=Q3Out Q3=Q3;
run;

data Want;
merge Have Q3Out;
by Group;
if N > Q3;
run;

proc print data=Want;
var Group N Q3;
run;

I don't fully understand if you want a histogram for each group or if you want one histogram that combines all the data across groups.  I think the first. If so, you can use PROC SGPANEL and PANELBY Group, or if you want many small histograms (not paneled), use PROC SGPLOT and BY Group.

 

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
  • 6 replies
  • 885 views
  • 0 likes
  • 4 in conversation