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

Hi, 

 

I am having problem in passing fomatted values in if condition. 

I have below TRTP values in my count dataset:

Capture 1.PNG

 

And I want to create another variable by using below calculation.

data count1;
	set count;
	if TRTP eq "A" then c2=count/Count1*100;
run;

but I am getting missing values for c2 variable, but log is clear.

 

Is there anything I am missing there?

 

Thanks,

Adithya

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your code compares TRTP to "A", but if TRTP is formatted, it may have underlying values different than what you see.

 

Any such comparison

 

if TRTP eq "A"

uses the unformatted values, not the formatted values. So the comparison would fail, even if it LOOKS LIKE your variable TRTP has value "A".

 

So just to make up an example, if the format $TRT1. is something like this:

 

proc format;
    value $trt "A","B","Q","T"="A";
run;

Then the comparison you would want to do is

 

if TRTP in ("A","B","Q","T")

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Your code compares TRTP to "A", but if TRTP is formatted, it may have underlying values different than what you see.

 

Any such comparison

 

if TRTP eq "A"

uses the unformatted values, not the formatted values. So the comparison would fail, even if it LOOKS LIKE your variable TRTP has value "A".

 

So just to make up an example, if the format $TRT1. is something like this:

 

proc format;
    value $trt "A","B","Q","T"="A";
run;

Then the comparison you would want to do is

 

if TRTP in ("A","B","Q","T")

 

--
Paige Miller
ballardw
Super User

To compare a value to a formatted value explicitly use the format:

 

If put(trtp,$trt1.) = 'A' then <whatever>;

FreelanceReinh
Jade | Level 19
@ballardw wrote:

To compare a value to a formatted value explicitly use the format:

 

If put(trtp,$trt1.) = 'A' then <whatever>;


 

Another option is to use the format implicitly:

if vvalue(trtp)='A' then ...

 (See VVALUE function. Be careful, however, when using this for unformatted numeric variables. In that case the default format BEST12. will apply.)