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;
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;
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;
Most likely the best way, I was unsure how format can be used for an umbrella "other" term thank you
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.