BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlm155
Obsidian | Level 7

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:

NameGrade (original values)
ABC1
DEF3
GHI4
JKL2

 

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:

NameGrade (formatted values)
ABC2
DEF1
GHI1
JKL2

 

Why doesn't this change the 2nd and 3rd row grades as shown below?

NameGrade (formatted values)
ABC2
DEF2
GHI2
JKL2

 

Thanks in advance for the help.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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).

 

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

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
Obsidian | Level 7
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?
Patrick
Opal | Level 21

@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.

mlm155
Obsidian | Level 7
Great, thanks!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
LIBNAME 101

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.

Discussion stats
  • 4 replies
  • 973 views
  • 1 like
  • 2 in conversation