So I am trying to do a proc freq for data that looks like this
id_num race
xxx 1
xxx 2
xxx 3
xxx 4
So when I do proc freq on race I want to the display to show actual races instead of 1,2,3,4 like white, black, asian, hispanic.
I have tried a few things (replacing values but that didn't work at all) but can't get anything close so all I really have is.
proc freq data=test;
tables race;
title;
footnote;
run;
which brings up
0 | 3772 | 0.98 | 3772 | 0.98 |
1 | 185936 | 48.20 | 189708 | 49.18 |
2 | 139248 | 36.10 | 328956 | 85.28 |
3 | 9606 | 2.49 | 338562 | 87.77 |
4 | 13978 | 3.62 | 352540 | 91.39 |
5 | 27078 | 7.02 | 379618 | 98.41 |
6 | 6127 | 1.59 | 385745 | 100.00 |
Frequency Missing = 16 |
but I
What you are looking for is a format.
You define the values with proc format:
Proc format;
value race
1='White'
2='Black'
3='Native American'
/* continue as needed*/
;
run;
Use by
proc freq data=test;
tables race;
format race race.;
run;
Note: the FORMAT reference ends in a period to tell SAS that it is a format not a variable.
What you are looking for is a format.
You define the values with proc format:
Proc format;
value race
1='White'
2='Black'
3='Native American'
/* continue as needed*/
;
run;
Use by
proc freq data=test;
tables race;
format race race.;
run;
Note: the FORMAT reference ends in a period to tell SAS that it is a format not a variable.
Hi,
Using a format should produce the results you want:
/* create the format */
proc format;
value racefmt
1 = 'white'
2 = 'black'
3 = 'asian'
4 = 'hispanic';
run;
/* source data */
data test;
length id_num $5 race 8.;
input id_num race;
datalines;
aaa 1
bbb 2
ccc 3
ddd 4
;
/* display using format */
proc freq data = test ;
tables race ;
format race racefmt.;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: