BookmarkSubscribeRSS Feed
KevinC_
Fluorite | Level 6
Hello everyone,

I have a general question about proc format. I am not writing a program or trying to fix an error. I just don't understand how the Value statement know which field it should look at.

Here is an example from a sas manual:

Data carsurvey;
Infile 'c:\mydata\cars.dat';
Input Age Sex Income Color $;

Proc Format;
value gender 1 = 'Male'
2 = 'Female';
value agegroup 13 -< 20 ='Teen'
20 -< 65 = 'Adult'
65 - High = 'Senior';
value $col 'W' = 'White'
'B' = 'Blue'
'Y' = 'Yellow';

My question is how does each Value statement know which field it should look at? For example, the first value statement generates a numeric format "Gender" for sex. But where do we tell it to look at the field sex?

Thanks for your input!
3 REPLIES 3
KevinC_
Fluorite | Level 6
for some reason it truncated my posting.. here is the rest

Proc Format;
value gender 1 = 'Male'
2 = 'Female';
value agegroup 13 - 20 = 'Teen'
20 - 65 = 'Adult'
65 - High = 'Senior';
value $col 'W' = 'White'
'B' = 'Blue'
'Y' = 'Yellow';

My question is how does each Value statement know which field it should look at? For example, the first value statement generates a numeric format "Gender" for sex. But where do we tell it to look at the field sex?

Thanks for your input!
Cynthia_sas
SAS Super FREQ
Hi:
A SAS user-defined format (what you create with either a VALUE statement or a PICTURE statement) is
1) DEFINED with PROC FORMAT
once defined, the format just sits in the format catalog until
2) USED in a FORMAT statement or a FORMAT= option in some procedures (like PROC REPORT or PROC TABULATE).

So DEFINING the format is only half of the "magic" -- the other "magic" happens when you USE the format. It is the USAGE step that makes the link between the format and the data. Information about the format is stored in the descriptor portion of the SAS dataset, if you assign the format when you read the data. If you use the format in a reporting procedure, then the format is used for that procedure and that procedure only.

For example, I could have these 2 formats for age. The PROC FORMAT step just DEFINES the formats. The next 2 steps USE the formats.

cynthia
[pre]
proc format;
value agefmt 11-14 = 'Cannot Drive'
15-high = 'Can Drive';

value agestat 11-12 = 'Pre-teen'
13-14 = 'Teenager'
15-high = 'Young Adult';
run;

ods listing;
proc freq data=sashelp.class;
title 'Using AGEFMT format';
tables age;
format age agefmt.;
run;

proc means data=sashelp.class;
title 'Using AGESTAT format';
class age;
var height;
format age agestat.;
run;
[/pre]
KevinC_
Fluorite | Level 6
Cynthia,

Thank you for the detailed explanation as always. Your input is always appreciated!

Kevin

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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