Help using Base SAS procedures

Proc Format Question

Reply
Regular Contributor
Posts: 173

Proc Format Question

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!
Regular Contributor
Posts: 173

Re: Proc Format Question

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!
SAS Super FREQ
Posts: 8,742

Re: Proc Format Question

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]
Regular Contributor
Posts: 173

Re: Proc Format Question

Cynthia,

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

Kevin
Ask a Question
Discussion stats
  • 3 replies
  • 102 views
  • 0 likes
  • 2 in conversation