converting a pattern of string to spaces in DataStage 11.7 - datastage

i need to convert a pattern of digits in an amount to spaces. like if i have all 9s then that should be converted to '', but if 9 is part of a number then it should not convert. For eg: 9, 99, 99.99, 9.999, 999.9..etc these should be converted to '', but if the amount is 90, 119, 291, 889, 100.99, 999.11 then it should not convert. CONVERT() is not working, so i tried to COUNT(AMT,9)=LEN(AMT). I think this won't work as LEN() will count DOT in the decimal posItion. So count (9.99, 9) would be 3 but LEN(9.99) would be 4.
My current code in DataStage 11.7 has IF CONVERT('9','', AMT) ='' THEN 0 ELSE AMT
Please help me with solution.

How about If Len(Convert("9","",AMT)) = 0 Then "" Else AMT

Related

Array prefix(while:) looping different number of times for same logic. (unable to comprehend)

Here is the shot of the playground where I am trying to print all the even numbers until you reach an odd one in 3 ways and I don't understand why there are different number of times it looped
From my understanding it should loop only 7 times because there are 6 even numbers in the starting and the 7th time there is an odd number which must terminate the loop but we have gotten 8 times in one case ! Why ?
Also quite literally the second and third way are same but still there is a difference in the number of times the loop was executed.
This, I don't understand.
===== EDIT =======
I was asked for text form of the code so here it is
import UIKit
// First way
var arr = [34, 92, 84, 78, 90, 42, 5, 89, 64, 32, 30].prefix { num in
return num.isMultiple(of: 2)
}
print(arr)
// Second way
var arr2 = [34, 92, 84, 78, 90, 42, 5, 89, 64, 32, 30].prefix(while: {$0.isMultiple(of: 2)})
print(arr2)
//Third way (almost second way but directly prinitng this time)
print([34, 92, 84, 78, 90, 42, 5, 89, 64, 32, 30]
.prefix(while: {$0.isMultiple(of: 2)}))
The message of "(x times)" isn't really saying how many times a line is executed in a loop.
Think of it like this, sometimes the playground want to output multiple messages on the same line, because two things are being evaluated on that line. This happen the most often in loops, where in each iteration a new thing is evaluated, and Xcode wants to display that on the same line, but can't, so can only display "(2 times)".
You can also see this happen in other places, like closures that are on the same line:
let x = Optional.some(1).map { $0 + 1 }.map { String($0) } // (3 times)
Here, the 3 things that are evaluated are:
x
$0 + 1
String($0)
Another example:
func f() { print("x");print("y") } // (2 times)
f()
Normally, each print statement will have some text displayed on the right, won't they? But since they are on the same line, Xcode can only show "(2 times)".
The same thing happens in this case:
var arr2 = [34, 92, 84, 78, 90, 42, 5, 89, 64, 32, 30].prefix(while: {$0.isMultiple(of: 2)})
There are 8 things to evaluate. The closure result is evaluated 7 times, plus once for the value of arr2.
If you put the variable declaration and the closure on separate lines, then Xcode can show the value of the variable on a separate line, which is why the number is one less in the two other cases.
To illustrate this graphically:
You are forcing Xcode to combine the two boxed messages into one single line. Xcode can't usefully fit all that text onto one single line, so the best it can do is "(8 times)".
I believe these are just artifacts of how playgrounds work. With a little re-formatting I get "7 times" in all three variations:
let data = [34, 92, 84, 78, 90, 42, 5, 89, 64, 32, 30]
let arr = data.prefix {
$0.isMultiple(of: 2)
}
print(arr)
let arr2 = data.prefix(while: {
$0.isMultiple(of: 2)
})
print(arr2)
print(data.prefix(while: {
$0.isMultiple(of: 2)
}))

How to detect 4 digit using regexp

How do I get the year (4 digits) when given a source code, I can only detect the day (29), but could not detect the year(1997). There is something wrong in my regexp checking.
age = regexp(CharData,'(\d{1,4})','match','once')
For example,
Registered On
March 29, 1997
Desired output: 1997
Error output: 29
for i = 1:2
data2=fopen(strcat('DATA\PRE-PROCESS_DATA\F22_TR\f22_TR_pdata_',int2str(i),''),'r')
CharData = fread(data2, '*char'); %read text file and store data in CharData
fclose(data2);
age = regexp(CharData,'(\d{4})','match','once')
end
file : f22_TR_pdata_1 --> Registered On
June 24, 1997
file : f22_TR_pdata_2 --> Registered On
March 29, 1997
Age: 1997
To only grab four digits
age = regexp(CharData,'(\d{4})','match','once')
Doing d{1,4} means look for numbers with a length between 1 and 4. Meaning, 1, 29, 123, 4444 would all match because their length is between 1 and 4
d{4} says, get me the number with exact length of 4. Meaning, 1997, 2001, 1800 would all match.

"Client_Text_IO.File_Type must be declard" getting this error in PL/SQL Oracle form

My line of codes are:
PROCEDURE LOAD_DATA IS
FILE_LOG Client_Text_IO.File_Type;
LINE_LOG VARCHAR(32767);
v_txt varchar(32767);
v_counter number(12) := 0;
BEGIN
file_log := Client_Text_IO.fopen(file_upload.origin, 'r');
END;
I am wokring first time with Oracle form. I have no any idea about it. I have almost done my work but I am getting an error at compile time. Complete error description,
Error 201 at line 2, column 11
identifier 'CLIENT_TEXT_IO.FILE_TYPE' must be declared
Error 0 at line 2, column 11
Item ignored
Error 320 at line 12, column 2
the declaration of the type of this expression is incomlete or malformed
Error 0 at line 12, column 2
Statement ignored
Error 320 at line 14, column 3
the declaration of the type of this expression is incomplete or malformed
Error 0 at line 14, column 3
Statement ignored
Error 201 at line 20, column 6
identifier 'V_TEXT' must be declared
Error 0 at line 20, column 3
Statement ignored
Error 320 at line 24, column 24
the declaration of the type of this expression is incomplete or malformed
Error 0 at line 30, column 2
Statement ignored
You need to attach the webutil.pll library to the form.

How to calculate a Mod b in Casio fx-991ES calculator

Does anyone know how to calculate a Mod b in Casio fx-991ES Calculator. Thanks
This calculator does not have any modulo function. However there is quite simple way how to compute modulo using display mode ab/c (instead of traditional d/c).
How to switch display mode to ab/c:
Go to settings (Shift + Mode).
Press arrow down (to view more settings).
Select ab/c (number 1).
Now do your calculation (in comp mode), like 50 / 3 and you will see 16 2/3, thus, mod is 2. Or try 54 / 7 which is 7 5/7 (mod is 5).
If you don't see any fraction then the mod is 0 like 50 / 5 = 10 (mod is 0).
The remainder fraction is shown in reduced form, so 60 / 8 will result in 7 1/2. Remainder is 1/2 which is 4/8 so mod is 4.
EDIT:
As #lawal correctly pointed out, this method is a little bit tricky for negative numbers because the sign of the result would be negative.
For example -121 / 26 = -4 17/26, thus, mod is -17 which is +9 in mod 26. Alternatively you can add the modulo base to the computation for negative numbers: -121 / 26 + 26 = 21 9/26 (mod is 9).
EDIT2: As #simpatico pointed out, this method will not work for numbers that are out of calculator's precision. If you want to compute say 200^5 mod 391 then some tricks from algebra are needed. For example, using rule
(A * B) mod C = ((A mod C) * B) mod C we can write:
200^5 mod 391 = (200^3 * 200^2) mod 391 = ((200^3 mod 391) * 200^2) mod 391 = 98
As far as I know, that calculator does not offer mod functions.
You can however computer it by hand in a fairly straightforward manner.
Ex.
(1)50 mod 3
(2)50/3 = 16.66666667
(3)16.66666667 - 16 = 0.66666667
(4)0.66666667 * 3 = 2
Therefore 50 mod 3 = 2
Things to Note:
On line 3, we got the "minus 16" by looking at the result from line (2) and ignoring everything after the decimal. The 3 in line (4) is the same 3 from line (1).
Hope that Helped.
Edit
As a result of some trials you may get x.99991 which you will then round up to the number x+1.
You need 10 ÷R 3 = 1
This will display both the reminder and the quoitent
÷R
There is a switch a^b/c
If you want to calculate
491 mod 12
then enter 491 press a^b/c then enter 12. Then you will get 40, 11, 12. Here the middle one will be the answer that is 11.
Similarly if you want to calculate 41 mod 12 then find 41 a^b/c 12. You will get 3, 5, 12 and the answer is 5 (the middle one). The mod is always the middle value.
You can calculate A mod B (for positive numbers) using this:
Pol( -Rec( 1/2πr , 2πr × A/B ) , Y ) ( πr - Y ) B
Then press [CALC], and enter your values for A and B, and any value for Y.
/ indicates using the fraction key, and r means radians ( [SHIFT] [Ans] [2] )
type normal division first and then type shift + S->d
Here's how I usually do it. For example, to calculate 1717 mod 2:
Take 1717 / 2. The answer is 858.5
Now take 858 and multiply it by the mod (2) to get 1716
Finally, subtract the original number (1717) minus the number you got from the previous step (1716) -- 1717-1716=1.
So 1717 mod 2 is 1.
To sum this up all you have to do is multiply the numbers before the decimal point with the mod then subtract it from the original number.
Note: Math error means a mod m = 0
It all falls back to the definition of modulus: It is the remainder, for example, 7 mod 3 = 1.
This because 7 = 3(2) + 1, in which 1 is the remainder.
To do this process on a simple calculator do the following:
Take the dividend (7) and divide by the divisor (3), note the answer and discard all the decimals -> example 7/3 = 2.3333333, only worry about the 2. Now multiply this number by the divisor (3) and subtract the resulting number from the original dividend.
so 2*3 = 6, and 7 - 6 = 1, thus 1 is 7mod3
Calculate x/y (your actual numbers here), and press a b/c key, which is 3rd one below Shift key.
Simply just divide the numbers, it gives yuh the decimal format and even the numerical format. using S<->D
For example: 11/3 gives you 3.666667 and 3 2/3 (Swap using S<->D).
Here the '2' from 2/3 is your mod value.
Similarly 18/6 gives you 14.833333 and 14 5/6 (Swap using S<->D).
Here the '5' from 5/6 is your mod value.

Display Superscript in SSRS reports

I m working on SSRS 2008.
i want to display date as 1st January 2011..
but "st" should be in superscipt ..
not like "1st".
is there any way to display "st", "nd","rd" and "th" in superscipt without installing any custom font type(other Font Type).
just copy and paste from the following list:
ABC⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁼ ⁽ ⁾
ABC₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₌ ₍ ₎
ABCᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ
ABCᴬ ᴮ ᴰ ᴱ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴼ ᴾ ᴿ ᵀ ᵁ ᵂ
ABCₐ ₑ ᵢ ₒ ᵣ ᵤ ᵥ ₓ
ABC½ ¼ ¾ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ № ℠ ™ © ®
ABC^ ± ¶
Maybe...
You are limited to what can be done with String.Format. Font size and spacing also refer to the whole text box. So it isn't "native"
However, superscript is unicode so you may be able to to do it with some fancy expression that concatenate characters. I'd suggest custom code.
I haven't tried this, but these articles mention it
http://beyondrelational.com/blogs/jason/archive/2010/12/06/subscripts-and-superscripts-in-ssrs-reports.aspx
http://www.codeproject.com/KB/reporting-services/SSRSSuperscript.aspx
I am not looking for credit here as above solution has answered it for you but for beginners sake, I use a code function within my report.
So in my SQL say I have Number field, then I add a new field OrdinalNumber:
SELECT ..., Number,
CASE WHEN (Number % 100) BETWEEN 10 AND 20 THEN 4
WHEN (Number % 10) = 1 THEN 1
WHEN (Number % 10) = 2 THEN 2
WHEN (Number % 10) = 3 THEN 3
ELSE 4 END AS OrdinalNumber,
...
Then my code function:
Function OrdinalText(ByVal OrdinalNumber As Integer) As String
Dim result As String
Select Case OrdinalNumber
Case 1
result = "ˢᵗ"
Case 2
result = "ⁿᵈ"
Case 3
result = "ʳᵈ"
Case Else
result = "ᵗʰ"
End Select
Return result
End Function
Then in the report textbox I use the expression:
=CStr(Fields!Number.Value) & Code.OrdinalText(Fields!OrdinalNumber.Value)