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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 595 views
  • 0 likes
  • 3 in conversation