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

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

Race Code RACE Frequency Percent Cumulative
Frequency Cumulative
Percent
037720.9837720.98
118593648.2018970849.18
213924836.1032895685.28
396062.4933856287.77
4139783.6235254091.39
5270787.0237961898.41
661271.59385745100.00
Frequency Missing = 16

 

 

but I

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

evp000
Quartz | Level 8

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;

 

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!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 859 views
  • 0 likes
  • 3 in conversation