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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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