Program isn't giving correct results - case when (SAS) - sas

/* FLAG_MISMATCH_PAID*/
(CASE
WHEN t1.Paid=t2.PAID_AMT THEN "TRUE"
ELSE "FALSE"
END) AS FLAG_MISMATCH_PAID
This works when I am using other variables, but for some reason I am getting incorrect TRUE/FALSE results when I use this code. I thought maybe there was some issues with numbers beyond the hundreds unit so I tried using round (x, .01), but correcting for that made no difference.
Why would two numbers that are exactly the same still give me a "FALSE" result? (i.e. t1.Paid = $106,115.23 and t2.PAID_AMT = $106,115.23, and it is flagged as FALSE, yet t1.Paid =$57,242.11 and t2.PAID_AMT = $57,242.11 is TRUE)

Related

How to give if condition for propercase and uppercase in sap crystal report

I am getting two values one is printing Cash and other is printing CASH in sap crystal report. Now, I want that wherever Cash is showing at that time value should be false while if CASH is printing then the value should show true. So, for that I added the formula but didnt work,
here is my formula,
if(ProperCase({TmpSalesBillInstallmentReport.PaymentType}) = true)
then {TmpSalesBillInstallmentReport.PaymentType}= '0'
else if(UpperCase({TmpSalesBillInstallmentReport.PaymentType}) = true)
{TmpSalesBillInstallmentReport.PaymentType} = '1'
This formula is not working, even getting error i.e. A Boolean Is Required Here(indicating on the first line)
I surfing in net but didnt get related question also.
IF {TmpSalesBillInstallmentReport.PaymentType} = "CASH" Then True ELSE False;
Note: A Crystal formula cannot assign a value to a database field. The field value is Read Only!
UpperCase() function is not a test that returns true or false. It simply returns the text argument after converting it to all upper case.
You might have a setting causing comparisons to be case insensitive.
See: http://www.plumblineconsulting.com/crystal-reports-and-case-sensitivity-of-database-records/

Should I reimplement the logic in property based test?

Let's say there is a function to determine if a button should be visible.
fun isButtonVisible(fitlers: List<Filters>, results: List<Shop>, isLoading: Boolean) {
return fitlers.isNotEmpty() && results.isEmpty() && !isLoading
}
Now I would like to test this function using PBT like:
"the button should be visible if filters is not empty and results is empty and is not loading" {
forAll { filters: List<Filters>, results: List<Shop>, isLoading: Boolean ->
val actual = isButtonVisible(filters, results, isLoading)
// Here reimplement the logic
val expected = filters.isNotEmpty() && results.isEmpty() && !isLoading
assertThat(actual).isEqual(expected)
}
}
It seems that I just reimplement the logic again in my test, is this correct? If not, how can I come up with another properties if the logic is just simple combinations of several flags?
that is not right.
you should not have to calculate what the expected value should be during the test, you should know what the result should be, set it as such and compare it against the actual result.
Tests work by calling the method you want to test and comparing the result against an already known, expected value.
"the button should be visible when filters are not empty, results is empty, isLoading is false " {
forAll { filters: List<Filters>, results: List<Shop>, isLoading: Boolean ->
val actualVisibleFlag = isButtonVisible(filters, results, isLoading)
val expectedVisibleFlag = true
assertThat(actualVisibleFlag ).isEqual(expectedVisibleFlag )
}
}
Your expected value is known, this is the point I am trying to make.
For each combination of inputs, you create a new test.
The idea here is that when you have a bug you can easily see which existing test fails or you can add a new one which highlights the bug.
If you call a method, to give you the result of what you think you should get, well, how do you know that method is correct anyway? How do you know it works correctly for every combination?
You might get away with less tests if you reduce your number of flags maybe, do you really need 4 of them?
Now, each language / framework has ( or should have ) support for a matrix kind of thing so you can easily write the values of every combination

Only one IF ELSE statement working SAS

Can someone explain to me why only the first IF ELSE statement in my code works? I am trying to combine multiple variables into one.
DATA BCMasterSet2;
SET BCMasterSet;
drop PositiveLymphNodes1;
if PositiveLymphNodes1 = "." then PositiveLymphNodes =
put(PositiveLymphNodes2, 2.);
else PositiveLymphNodes = PositiveLymphNodes1;
if PositiveLymphNodes2 = "." then new_posLymph = put(PositiveLymphNodes,
2.);
else new_posLymph = PositiveLymphNodes2;
RUN;
Here is a nice screenshot of what the incorrect output looks like:OUTPUT
Thanks!
Hard to say without seeing all of your data, but I have a suspicion: is positivelymphnodes1 character or numeric? Is it ever actually equal to "."?
If you are trying to say "if PositiveLymphNodes1 is missing", then you can say that this way:
if missing(positivelymphnodes1) then ...
You can also do the same thing using coalesce or coalescec (the latter is character, the former numeric, in its return value). It chooses the first nonmissing argument. - so if the first argument is missing, it chooses the second.
positiveLymphNodes = coalescec(PositiveLymphNodes1, put(positiveLymphNodes2,2.));
new_posLymph = coalescec(positiveLymphNodes2, put(positiveLymphNodes,2.));
I would be curious why you're using put only in one place and not the other - use it in both or neither, I would suggest.

Crystal Reports Else If statement

I can't figure out why this if statement won't work.
I have a DateTime field DATEFROM and a String parameter (it HAS to be String) periodEnd.
I would like to calculate percentages depending if these two dates have 1, 2, 3 or more years difference.
When I use this formula I get either "100%" or "-" and never the other two options. It's like CR calculates the first IF and if it's true then: "100%" but if it's false, it never checks for the rest of the Else Ifs and goes dirreclty to Else
StringVar percentage:="";
If (cDate({?periodEnd})-{TABLE.DATEFROM})<=1 Then
percentage:="100%"
Else If (cDate({?periodEnd})-{TABLE.DATEFROM})<=2 Then
percentage:="66%"
Else If (cDate({?periodEnd})-{TABLE.DATEFROM})<=3 Then
percentage:="33%"
Else
percentage:="-"
Any idea?
a) I assume you already made sure your periodend format matches with what cdate interprets?
If you just subtract them, Crystal by default returns the number of days between.
Two ways you can do year:
datediff("yyyy",cDate({?periodEnd},{TABLE.DATEFROM})
or
year(cDate({?periodEnd})-year({TABLE.DATEFROM})
b) You've also no doubt accounted for when your {TABLE.DATEFROM} is greater than cDate({?periodEnd} and you have a negative result?
Not sure if the following is the behavior you would want, but I'm throwing it in for your information
ABS(datediff("yyyy",cDate({?periodEnd},{TABLE.DATEFROM}))
**make sure you check the help file for the datediff codes ("yyyy" etc) as they are not quite instinctive and can trip you up when you think you're using the obvious one

what is wrong with my if -condition?

So I've been trying to figure out what is wrong with my if-condition, but I am getting nowhere. I am still new to R, so maybe I am not understanding some very basic concept here?
I have a dataframe (dc) to which I appended a column with logical "FALSE". Now I want to change each FALSE into a TRUE based on the values in two columns of dc (dc$Probe and dc$Resp) that I specified using regexpr().
What it does so far is that, for both if-conditions, it changes each FALSE into TRUE regardless of the values in column 5 of dc. When I run the if-conditions seperately, I can see that they seem to be working fine on the OR-part of the condition, meaning the code only generates TRUE when the strings in dc$Probe match one of the strings specified in the OR-part. However, the AND-part seems to be ignored? Thus, when I run the complete code, I get a column with only TRUE, which is not what I want.
Edit: I should get a TRUE only if the string in Probe ends in a certain pattern (as specified in either of the two if conditions I wrote) and if the corresponding value in Resp is a "100" for the patterns specified in my first condition or a "200" for the patterns specified in my second condition. Thus, for strings ending in (sg|s|w1|w3|s1|s2), Resp must be "100" to get a TRUE and for strings ending in (\d\dg|\d\d), Resp must be "200" to get a TRUE. All other cases should be FALSE. For example, if a string ends in s1 and the corresponding value in Resp is 200, the code should return FALSE.
Edit: Some example data:
>dc<-data.frame(Subject=rep("SN",6), item.c=(1:6), Stim=c("XYZc02s03","XYZc01s30","XYZc02s29", "XYZc01s38", "XYZc02s11", "XYZc06w21"), Probe=c("XYzf02s03","XYZf01s30g","XYZf02s29w1","XYZf01s38sg","XYZf02s11s","XYZv06w21s1"), Resp=c(200, 100, 100, 100, 100, 200))
This is my code:
>dc$Resp<-as.character(dc$Resp) #column 5 in dc
dc$Probe<-as.character(dc$Probe)
dc$correct_response <- FALSE
for (i in 1:nrow(dc)) {
if (regexpr("^.*sg$", dc$Probe[i])==1 || regexpr("^.*s$", dc$Probe[i])==1 || regexpr("^.*w1$", dc$Probe[i])==1 || regexpr("^.*w3$", dc$Probe[i])==1 || regexpr("^.*s1$", dc$Probe[i])==1 || regexpr("^.*s2$", dc$Probe[i])==1 && dc[i,5]=="100") {(dc$correct_response[i]<- TRUE)}
if (regexpr("^.*\\d\\dg$", dc$Probe[i])==1 || regexpr("^.*\\d\\d$", dc$Probe[i])==1 && dc[i,5]=="200") {(dc$correct_response[i]<- TRUE)}
}
Is there something wrong with the regular expressions I am using? I checked them with glob2rx() and it seems like they are ok...Is my use of "OR" (||) or/and "AND" (&&) incorrect? How do I implement the AND-part properly? I have also tried the following code for the AND-part, but it didn't change anything:
regexpr("200", dc$Resp[i])==1
I read the R-help on regular expressions and control flow, but I still don't see what I am doing wrong. Consulting other webpages on logical expressions did not help me either.
Please help!
Im wondering if it can all be reduced to the following:
dc<- read.table(header=T,text="Subject item.c Stim Probe Resp
SN 1 XYZc02s03 XYzf02s03 200
SN 2 XYZc01s30 XYZf01s30g 100
SN 3 XYZc02s29 XYZf02s29w1 100
SN 4 XYZc01s38 XYZf01s38sg 100
SN 5 XYZc02s11 XYZf02s11s 100
SN 6 XYZc06w21 XYZv06w21s1 200")
cond1<-regexpr("^.*(sg|s|w1|w3|s1|s2)$", dc$Probe)==1 & dc$Resp==100
cond2<-regexpr("^.*(\\d\\dg|\\d\\d)$", dc$Probe)==1 & dc$Resp==200
dc$correct_response<-cond1|cond2
For one thing, you are missing a logical operator between the 2nd and 3rd clauses of your first if statement.