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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.