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.
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;
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.
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
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;
Reeza,
As always, you have a solution to the question. I attached the solution output.
Thanks
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;
@ReezaI would say the "standard" SAS way to do this is by using features of PRELOADFORMAT and NOTSORTED value label formats.
@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.
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.