BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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...?
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
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!
ChrisNZ
Tourmaline | Level 20
Look at the VVALUE and VVALUEX functions, you should find them very useful.
deleted_user
Not applicable
oh, thanks. I never heard of these. I will look them up now.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1010 views
  • 0 likes
  • 4 in conversation