Help using Base SAS procedures

Changing the display of Proc Freq

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Changing the display of Proc Freq

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


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 10,500

Re: Changing the display of Proc Freq

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


All Replies
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 10,500

Re: Changing the display of Proc Freq

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.

Contributor
Posts: 74

Re: Changing the display of Proc Freq

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;

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 251 views
  • 0 likes
  • 3 in conversation