BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abrice520
Obsidian | Level 7

For my SAS class I have to create a format called "$StateCd" that will apply to the variable StateCd (that I have to rename from State), that will change all the observations named "IOWA" to a 2 character long "IA" . This was my attempt:

 

PROC FORMAT LIBRARY= WORK;
VALUE $StateCd
		"IOWA"= "IA";
RUN;

DATA WORK.Contact_IA;
     SET	HypImpt.IowaResidents (RENAME= (State= StateCd));
FORMAT StateCd $StateCd2.;
RUN;

The format changed all the "IOWA" to "IA" but the length is still 4 like it was before applying the format. This is my first time trying to use a user defined format, what am I doing wrong?

Thank you so much,

Amanda

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Another way to apply a format is to use it when creating a new variable.  For example:

 

data want;
set HypImpt.IowaResidents;
StateCd = put(state, $stateCd2.);
* drop state;
run;

This program assumes that you have already run the PROC FORMAT.  Dropping STATE is optional.

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

A SAS format just applies to how a variable value is displayed. The underlying value stored in the variable is still IOWA hence it remains as 4 characters long. 

Astounding
PROC Star

Another way to apply a format is to use it when creating a new variable.  For example:

 

data want;
set HypImpt.IowaResidents;
StateCd = put(state, $stateCd2.);
* drop state;
run;

This program assumes that you have already run the PROC FORMAT.  Dropping STATE is optional.