BookmarkSubscribeRSS Feed
SM8
Obsidian | Level 7 SM8
Obsidian | Level 7

Hello,

 

I am fairly new at SAS. Currently, I am trying to use SAS to change the name of certain variables/values for differing outputs (proc freq, etc). For example, in my data set, race is categorized as 1, 2, 3, and so on. I would like to be able to use proc freq and get outputs where as for the variable of race, 1 would be outputted as white, 2 as black, 3 as asian, and so on. I thought that formats would be the proper way to do so but after formatting, my printouts still simply say 1, 2, 3.. for race.

 

Here is the code I used for formatting:

 

proc format;
value frace
1 = 'Black'
2 = 'White'
3 = 'Asian'
4 = 'NativeAM'
5 = 'HawaiianPI'
6 = 'Multi'
7 = 'Other'
;
value **bleep**egroup
1 = '<20'
2 = '20-24'
3 = '25-29'
4 = '30-34'
5 = '35-39'
6 = '40+'
;
value fethnicity
1 = 'Non-Hisp'
2 = 'Hisp'
;
value fmarital
1 = 'Single'
2 = 'Separated'
3 = 'Divorced'
4 = 'Widowed'
5 = 'Married'
;
value fincomegroup
1 = '<35000'
2 = '35000-49999'
3 = '50000-74999'
4 = '75000-99999'
5 = '100000 or more'
;
value feducat
0 = 'None'
1 = 'Less than HS'
2 = 'Less than HS'
3 = 'Less than HS'
4 = 'Less than HS'
5 = 'Less than HS'
6 = 'Less than HS'
7 = 'Less than HS'
8 = 'Less than HS'
9 = 'High School'
10 = 'High School'
11 = 'High School'
12 = 'High School'
13 = 'More than HS'
14 = 'More than HS'
15 = 'More than HS'
16 = 'More than HS'
17 = 'More than HS'
18 = 'More than HS'
22 = 'More than HS'
;
run;

 

 

data tmp1.identificationformats;
set tmp1.identification2;
format Race frace. Agegroup **bleep**egroup. Ethnicity fEthnicity. Marital fMarital. Income fIncomegroup. Educat fEducat.;
run;

 

Thanks so much!!

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Formats are the way to do this. So what happens when you try? Is there an error in the LOG? Does the PROC FREQ not show the format? Can you show us what happens?

--
Paige Miller
SM8
Obsidian | Level 7 SM8
Obsidian | Level 7

For some reason, the formats went through without error but all of the outputs for the code I ran continued to use the original values. However, I tried it again and it just worked! Thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 264 views
  • 0 likes
  • 2 in conversation