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

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.

 

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