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;
Do you want the formatted value to be in another variable or?
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.
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.