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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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