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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.