DATA Step, Macro, Functions and more

Referencing formatted value, how?

Reply
N/A
Posts: 0

Referencing formatted value, how?

If I have a variable that is attached to a format library, how do i reference the formatted value? For example,

if the variable is grade and contains the values like 100, 99, 98, 97...etc. and 90, 91, 92, 93...are As, 80, 81, 82...are Bs and so on. The value of the grade variable is 100, 99, 98...but the formatted values are A, B, C, D...etc. Instead of referencing the original value of grade, which are 100, 99, 98...I want to reference the values A, B, C...which are the values after attaching the variable to the format library. Is there a way of doing this? Or I have to reference 100, 99, 98...?
Super Contributor
Super Contributor
Posts: 3,174

Re: Referencing formatted value, how?

Referencing in a PROC, such as PROC PRINT, you would associate with a FORMAT statement. If you need to reference the "formatted value" in a DATA step, you need to use a PUT function with the variable and the output format coded as an argument.

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,743

Re: Referencing formatted value, how?

Hi:
Let's figure that your grade format is called GRFMT. So if you want to test the letter value instead of the number, your IF would be something like this:
[pre]
if put(numgrd,grfmt.) = 'A' then do;
....
end;
else if put(numgrd,grfmt.) = 'B' then do;
....
end;
[/pre]

or, you could just make a new variable:
[pre]
length newvar $1;
newvar=put(numgrd,grfmt.);

...and then...
if newvar = 'A' ...
[/pre]

cynthia
N/A
Posts: 0

Re: Referencing formatted value, how?

Wow! Thanks. I didn't know you could do that with format like that. I used a bad solution. I just wrote lots of if statements and created a new variable.

Thanks for the help!
PROC Star
Posts: 1,561

Re: Referencing formatted value, how?

Look at the VVALUE and VVALUEX functions, you should find them very useful.
N/A
Posts: 0

Re: Referencing formatted value, how?

oh, thanks. I never heard of these. I will look them up now.
Ask a Question
Discussion stats
  • 5 replies
  • 154 views
  • 0 likes
  • 4 in conversation