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.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 651 views
  • 0 likes
  • 4 in conversation