BookmarkSubscribeRSS Feed
JackZ295
Pyrite | Level 9

Is there a code that you can use within a proc freq procedure to find a range of values for a categorical variable? For example, if you are dividing work experience (years) into various categories (<=2, 3-9, 10-14, >15),  is there a way to find a range for the number of years worked? Thanks! 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

... find a range of values for a categorical variable?

 

Years worked is categorical. PROC FREQ will automatically find all levels in the data set, so it seems to me that you could then determine visually from the PROC FREQ output the "range" (although "range", "min" and "max" is not really defined for categorical variables).

 

 

--
Paige Miller
ballardw
Super User

Creating groups from a numeric sort of continuous variable is often done using a custom format.

Example:

proc format library=work;
value yearrange
0 - 2 = '<=2'
3 - 9 = '3 to 9'
10-14 = '10 to 14'
15 - high='15+'
;
run;

proc freq data=have;
   tables yearvariable;
   format yearvariable yearrange.;
run;

Above is designed to work with integer years. The proc format range descriptors on the left side of the = signs above include the ability to do strictly less than or strictly greater than using the < in conjunction with the - interval indicator.

 

A nice thing about formats is you could describe a different set of ranges such as 0 - 9 and 9+ and only have to change the format in proc freq or most other analysis procedures to use a different set of ranges.

Reeza
Super User
Are you looking for PROC RANK, which can create equal sized buckets or something else?
ballardw
Super User

@JackZ295 wrote:

Is there a code that you can use within a proc freq procedure to find a range of values for a categorical variable? For example, if you are dividing work experience (years) into various categories (<=2, 3-9, 10-14, >15),  is there a way to find a range for the number of years worked? Thanks! 


Likely time to provide example input data and the desired result for that input data.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 4878 views
  • 3 likes
  • 4 in conversation