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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.