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

I keep getting the output on racegrp, "Other" option displayed either in the middle or at the top of the result. see attached in details for sas code and output.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Code white as 1, black as 2, other as 3, and apply proc format.

 

proc format;
value race_fmt
1 = 'White'
2 = 'Black'
3 = 'Other';
run;

data have;
set have;
if race='White' then cat=1;
else if race='Black' then cat=2;
else cat=3;
run;

proc freq data=have;
table cat;
format cat race_fmt.;
run;

View solution in original post

7 REPLIES 7
Reeza
Super User

The standard way around this is to code the variables as numeric and use formats to apply the displayed value. 

 

You also don't say what you want, so this is a bit of a guess. 

abuanuazu
Fluorite | Level 6

Thank you Reeza for prompt response. To make clear, I want the the output table to produce as coded, White, Black, & Other in a sequence. 

 

Thanks

Reeza
Super User

Code white as 1, black as 2, other as 3, and apply proc format.

 

proc format;
value race_fmt
1 = 'White'
2 = 'Black'
3 = 'Other';
run;

data have;
set have;
if race='White' then cat=1;
else if race='Black' then cat=2;
else cat=3;
run;

proc freq data=have;
table cat;
format cat race_fmt.;
run;
abuanuazu
Fluorite | Level 6

Reeza,

 

As always, you have a solution to the question. I attached the solution output.

 

Thanks

Ksharp
Super User

Reeza's solution is a little bit of complicated. Create a new dummy variable  CAT and padding blanks before it .

 

data have;
set have;
length cat $ 40;
if race='White' then cat='  White';
else if race='Black' then cat=' Black' ;
else cat='Other';
run;

proc freq data=have;
table cat;
run;

 

data_null__
Jade | Level 19

@ReezaI would say the "standard" SAS way to do this is by using features of PRELOADFORMAT and NOTSORTED value label formats.

FreelanceReinh
Jade | Level 19

@abuanuazu: In your specific case you could have achieved the desired result even easier, without any additional steps:

proc freq data=have order=freq;
tables racegrp;
run;

The ORDER=FREQ option sorts the categories by descending frequency counts.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1792 views
  • 1 like
  • 5 in conversation