Hi,
Just wondering how the following proc format will work;
proc format;
value myFormat 1 = 2
2 = 2
3 = 1
4 = 1;
run;
Let the data be like:
Name | Grade (original values) |
ABC | 1 |
DEF | 3 |
GHI | 4 |
JKL | 2 |
Just came across something like this where the value and the formatted_value have same numbers (1 and 2).
When myFormat is applied to Grade, it gives correct results as:
Name | Grade (formatted values) |
ABC | 2 |
DEF | 1 |
GHI | 1 |
JKL | 2 |
Why doesn't this change the 2nd and 3rd row grades as shown below?
Name | Grade (formatted values) |
ABC | 2 |
DEF | 2 |
GHI | 2 |
JKL | 2 |
Thanks in advance for the help.
Bit guessing what you're asking but....
A format applied to a variable with change how the variable values get WRITTEN. The format does not change the value stored in the variable.
For this reason applying the format "twice" will give you twice the same result - because the internal value of the variable hasn't changed.
IF you want to change the internal value then you need to assign the formatted value to the variable. Something like:
new_var=put(var, myformat.);
Please note: A format will always return a string and though always be character. If you want to get numerical values then use the input function - input(put(var,myformat.),best32.) - or even better define and use an informat (done via Proc Format INVALUE).
Bit guessing what you're asking but....
A format applied to a variable with change how the variable values get WRITTEN. The format does not change the value stored in the variable.
For this reason applying the format "twice" will give you twice the same result - because the internal value of the variable hasn't changed.
IF you want to change the internal value then you need to assign the formatted value to the variable. Something like:
new_var=put(var, myformat.);
Please note: A format will always return a string and though always be character. If you want to get numerical values then use the input function - input(put(var,myformat.),best32.) - or even better define and use an informat (done via Proc Format INVALUE).
@mlm155 wrote:
Thanks. Just to make it clear: if the FORMAT is being applied in a DATA STEP, that would change the internal value, isn't it?
No, it would not. A format is really only changing how a value gets written not how it's stored.
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!
Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.
Find more tutorials on the SAS Users YouTube channel.