BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I want to add format to variable x .

When I look at values of X in data set b I see that the values are the formatted values and not the original values.

Why did it happen?

What is the way to solve it?

I want to keep have the original values of X (222,333,444,555)  but with a formatted values  in behind (abcd,efgh,aabb,ddnn)

 

Data a;
input x ;
cards;
222
333
444
555
;
Run;

proc format;
value FFmt
222='abcd'
333='efgh'
444='aabb'
555='ddnn'
;
Run;

Data b;
set a;
format x FFmt.;
Run;
4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Do you want the formatted value to be in another variable or?

Kurt_Bremser
Super User

The values never change by assigning a format, only the display. If you want to see both formatted and raw values in a dataset viewer, you need to have two variables, one with and one without the format.

ed_sas_member
Meteorite | Level 14

Hi @Ronein 

 

Does this answer your question?

proc format;
	invalue $in_FFmt '222'='abcd' '333'='efgh' '444'='aabb' '555'='ddnn';
	value   $FFmt 'abcd'=222 'efgh'=333 'aabb'=444 'ddnn'=555;
Run;

Data a;
	input x $in_FFmt.;
	cards;
222
333
444
555
;
Run;

title "Without format (= real stored value)";
proc print noobs data=a;
run;

title "With format";
proc print noobs data=a;
	format x $FFmt.;
run;
Tom
Super User Tom
Super User

Changing the format only changes how the data is displayed, it does not change the data.

Perhaps you want to use a different format that shows both the raw and formatted values (code and decode)?

proc format;
value FFmt_both
222='222 abcd'
333='333 efgh'
444='444 aabb'
555='555 ddnn'
;
Run;

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!

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
  • 4 replies
  • 633 views
  • 1 like
  • 5 in conversation