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

I am wondering if there is any very clever way of renaming the observations in a variable according to the frequency they appear, it has been a bit of a brain teaser for me today.

 

Imagine having the dataset

 

data have;


set have;


input ID Business $;


datalines;

1 Retail
2 Corporate
3 Retail
4 Retail
5 Retail
6 Corporate
7 SME
8 Retail
9 Retail
10 Corporate
;
run;

 

is there any way that you can change observations in the business variable if there is less than 10% representation in the variable

I.e. in a proc freq - variable SME would account for 10%, would there possibly be a code to say

 

data want;
set have;

if business(Obs)<10% then business="Other";

run;

 

it's sounding a little far fetched but if this is not possible, my question is can I have multiple constraints on the statement below:

 

data want;
set have;

if Business^= "Retail" or "Corporate"
then Business = "Other";

run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

What about a custom format?

 

data have;
input ID Business $15.;
datalines;
1 Retail
2 Corporate
3 Retail
4 Retail
5 Retail
6 Corporate
7 SME
8 Retail
9 Retail
10 Corporate
;
run;

proc format;
value $ business_type_fmt
'Retail' = 'Retail'
'Corporate' = 'Corporate'
other = 'Other';
run;

proc freq data=have;
table business;
format business $business_type_fmt.;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User

What about a custom format?

 

data have;
input ID Business $15.;
datalines;
1 Retail
2 Corporate
3 Retail
4 Retail
5 Retail
6 Corporate
7 SME
8 Retail
9 Retail
10 Corporate
;
run;

proc format;
value $ business_type_fmt
'Retail' = 'Retail'
'Corporate' = 'Corporate'
other = 'Other';
run;

proc freq data=have;
table business;
format business $business_type_fmt.;
run;
89974114
Quartz | Level 8

Most likely the best way, I was unsure how format can be used for an umbrella "other" term thank you

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1222 views
  • 4 likes
  • 2 in conversation