I'm currently using Crystal Reports 2013 to run reports. I'm having an issue with a formula that needs to look at an SAP order status and only print out a specific few. The SAP Order Status field is made up of 2 sections.
Section 1: 'A' 'B' 'C' 'D' (Only a single selection is pulled from
this list)
Section 2: 'E' 'F' 'G' 'H' (This can have multiple selections within
the Status)
Example Order #1111 Status: "A: F: G"
I currently have a formula that pulls the status of an order from the 1st Section.
if (isnull({user_status}) or
{user_status}=" " or
not ({user_status} like ["*A*", "*B*", "*C*", "*D*"])) then "N/A" else
if {user_status} like "*A*" then "A" else
if {user_status} like "*B*" then "B" else
if {user_status} like "*C*" then "C" else
if {user_status} like "*D*" then "D"
The above snippet would only bring in "A" for Order #1111 and omit "F" & "G".
I need assistance with a formula that would omit "A" and list out both "F" & "G".
I've tried the following:
if (isnull({user_status}) or
{user_status}=" " or
not ({user_status} like ["*E*", "*F*", "*G*", "*H*"])) then "N/A" else
if {user_status} like "*E*" then "E" else
if {user_status} like "*F*" then "F" else
if {user_status} like "*G*" then "G" else
if {user_status} like "*H*" then "H"
But that formula just returns the full "A; F; G" status.
Figured out the answer. (6/9/2020) I used the following code to create an array and loop through it pulling out only what I needed.
NumberVar Counter;
StringVar finalStatus:= "";
StringVar array statusList;
statusList:= split({user_status},";");
//Loop through array and only print out Status w/o No values
FOR Counter := 1 to UBound(statusList) DO
(if statusList[Counter] like ["E", "F", "G", "H"] then
finalStatus:= finalStatus+statusList[Counter]+";" else "");
finalStatus
Thanks for the input.
Related
I am pulling out survey participants comments from a dataset using prxmatch in SAS EG 7.1. There are a lot of comments that start with "No", it might just be no on its own or it might say no problems etc. I only want to filter these out if the string starts with "no", and not if "no" is contained elsewhere in the string so I have included the ^ metacharacter but I noticed some comments are being filtered out if they have "not" in them so I include \b after no for the word boundary however it is still filtering out strings that have "not" or "no" anywhere within the string.
Examples of what should match:
"No problems" "No"
Examples of what should NOT match:
"His name is STEVE not SPEVE" "I was mostly fine but I was not expecting to get a headache"
How do I stop this from happening? I've included my code, any help would be great.
data cclhd hnelhd islhd nbmlhd seslhd swslhd slhd wslhd mnclhd nnswlhd wnswlhd;
set work.schools_dataset;
where Comments ne " ";
if prxmatch ("m/^no\b|^nil|^none|^nop|all good|na|n\/a|n\.a/i",Comments) = 0 ;
keep ParticipantID FirstName Mobile VaxDate OperationID Venue Comments;
if operationid=108 then output work.cclhd;
else if operationid=109 then output work.hnelhd;
else if operationid=110 then output work.islhd;
else if operationid=111 then output work.nbmlhd;
else if operationid=113 then output work.seslhd;
else if operationid=114 then output work.swslhd;
else if operationid=115 then output work.slhd;
else if operationid=116 then output work.wslhd;
else if operationid=118 then output work.mnclhd;
else if operationid=120 then output work.nnswlhd;
else if operationid=122 then output work.wnswlhd;
run;
Try:
data cclhd hnelhd islhd nbmlhd seslhd swslhd slhd wslhd mnclhd nnswlhd wnswlhd;
set work.schools_dataset;
where Comments ne " ";
if prxmatch("/^no\b/i",comments) = 0;
keep ParticipantID FirstName Mobile VaxDate OperationID Venue Comments;
if operationid=108 then output work.cclhd;
else if operationid=109 then output work.hnelhd;
else if operationid=110 then output work.islhd;
else if operationid=111 then output work.nbmlhd;
else if operationid=113 then output work.seslhd;
else if operationid=114 then output work.swslhd;
else if operationid=115 then output work.slhd;
else if operationid=116 then output work.wslhd;
else if operationid=118 then output work.mnclhd;
else if operationid=120 then output work.nnswlhd;
else if operationid=122 then output work.wnswlhd;
what I am trying to accomplish is as follows:
I am trying to have an expression that returns a value "A" if 'apple' is anywhere in the string, and return value "B" if 'bell' is anywhere in the string.
if 'apple' or 'bell' is not in the string, then 'null'
eg, the column will have 'apple', 'bell', 'any other word' at different positions in the string and I need a formula that returns "A" if 'apple' in present and "B" if 'bell' is present
column value example:
'applebee'
'appletart'
'bellview'
'bellmont'
'apple fritter'
'freedom bell'
'bird'
'coffin'
'...'
desired outcome:
"A"
"A"
"B"
"B"
"A"
"B"
"null"
"null"
"null"
i have tried:
[description] contains 'INV' then 1
[description] contains 'VOL' then 2
else 'null'
maybe an if statement could work better?
What happens when you try:
if(lower([description]) contains 'apple') then ('A') else
if (lower([description]) contains 'bell') then ('B') else
(Null)
I'd like create specific condition "IF", but I don't know how.
I need create one scprit do something when user digit specifics numbers. For example:
If String = "" or String = 0 and > 5 Then.....
Script only do something if user digit: 1,2,3,4
Anybody know how to create it?
Here are a couple of ways.
Convert the string to a number and test the bounds:
If IsNumeric(someString) Then
i = CLng(someString)
If i >= 1 And i <= 4 Then
' Match
End If
End If
Use Select Case and you can specify multiple values to match:
Select Case someString
Case "1", "2", "3", "4"
' Match
End Select
Or, if you just want to do multiple individual tests, here's the basic If structure:
If someString = "1" Or someString = "2" Or someString = "3" Or someString = "4" Then
End If
I would like to ask about the if else expression in ireport jasper report. May I know is it possible to have multiple or more parameter in the if else statement?
(($P{endDate}.isEmpty()==true || $P{endDate}.equals(""))? "" :
" createDate>='" + $P{startDate} +"'" && " createDate<='" + $P{endDate} +"'")
Based on the code above, there are not allowed me to use "&&". It prompt out syntax error.
Besides that, May I know any solution to solve it? Thank you very much.
I'm assuming it's a query expression your trying to write. You probably would have to do something as follows:
Create a parameter for your dataset. This parameter should not be "prompted" and lets call it DATE_LIMIT_EXPRESSION. You should then set its default value as your expression. For example (if I a get what you meant), this could be your default expression:
"1" +
(($P{startDate}.isEmpty() == false) ? (" AND createDate >= " + $P{startDate}) : "") +
(($P{stopDate}.isEmpty() == false) ? (" AND stopDate <= " + $P{stopDate}) : "")
Now, your dataset query should be something like:
select
...
where $P!{DATE_LIMIT_EXPRESSION}
Just notice the "$P!" syntax. You can find more information about this in the Jasper Reports' documentation.
I have a string vector of user-input data containing strings. Now I need to make sure program won't execute if strings are different than specified few. Vector contains 4 fields and every has different condition:
vector[0] can only be "1" or "0"
vector[1] can only be "red" or "green
vector[2] can only be "1", "2" or "3"
vector[3] can only be "1" or "0"
I tried writing if for every condition:
if(tokens[0]!="1" || tokens[0]!="0"){
decy = "error";
}
else if(tokens[1]!="red" || tokens[1]!="green"){
decy = "error";
}
else if(tokens[2]!="1" || tokens[2]!="2" || tokens[2]!="3"){
decy = "error";
}
else if(tokens[3]!="1" || tokens[3]!="0"){
decy = "error";
}
else{
switch(){} //working code
}
return decy;
It always enters first if and returns error. I tried with if instead of else if but it doesn't work either. I checked vector[i] contents and it returns correct strings. No " " at the end of it etc. Removing else and releasing switch just makes program check first condition and ignore rest of it.
I'm probably doing something terribly wrong, but I can't find an answer on internet so I decided to ask here.
This line:
if(tokens[0]!="1" || tokens[0]!="0")
should be:
if(tokens[0]!="1" && tokens[0]!="0")
^^
The same goes for the rest of the if statements as well.
The conditions are invalid.
Any distinct value can satisfy your conditions.
You should use && instead of ||.
For example:
if (tokens[0] != "1" || tokens[0] != "0") {
Consider this line. If tokens[0] is "1", which is valid input, it will not satisfy the first condition, but it will satisfy the second. You only want to throw an error when the value is neither of the valid possible inputs.
This means that your condition should be:
if (tokens[0] != "1" && tokens[0] != "0") {
Same goes for all the others.
You should turn those || into &&. If the input can only be X or Y, this means that it is illegal when it is not X and not Y:
if (tokens[0] != "1" && tokens [0] !="0")
// ^^
The first if:
if(tokens[0]!="1" || tokens[0]!="0")
ALWAYS evaluates to true.