Retrieving count with leading zeros - xslt

I am retrieving to fetch the count of rows which I gor from SQL Server using a column. I am achieving it through
xsl:value-of select='format-number(count(//Report/ABC_Data/Details_Collection/Details/Sequence_Number),"#")'
But the issue is, I need it for 6 characters & if the count is just 2 digits, say 62, I need it as 000062. Any help on this please ?
Also is there a way to add two nodes (And pad it with leading zero's : length is 20)?
I am trying as
xsl:value-of select='format-number(sum(//Report/ABC_Data/Details_Collection/Details/Initial_Amount|Final_Amount),"$#.00")'>

Your number pattern needs to look like 000000 rather than using # characters:
format-number(62, '000000')
gives 000062.
You can use a node-set in sum: try something like:
sum((//Report/ABC_Data/Details_Collection/Details/Initial_Amount, //Report/ABC_Data/Details_Collection/Details/Final_Amount))
The outer set of brackets is for the sum function; the inner set is to define a (comma separated) node set sequence. Note that each XPath term could theoretically return a sequence of more than one value!

Related

Extract multiple substrings of numbers of a specific length from string in Google Sheets

I'd need to split or extract only numbers made of 8 digits from a string in Google Sheets.
I've tried with SPLIT or REGEXREPLACE but I can't find a way to get only the numbers of that length, I only get all the numbers in the string!
For example I'm using
=SPLIT(lower(N2),"qwertyuiopasdfghjklzxcvbnm`-=[]\;' ,./!:##$%^&*()")
but I get all the numbers while I only need 8 digits numbers.
This may be a test value:
00150412632BBHBBLD 12458 32354 1312548896 ACT inv 62345471
I only need to extract "62345471" and nothing else!
Could you please help me out?
Many thanks!
Please use the following formula for a single cell.
Drag it down for more cells.
=INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "))=8,
SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "),"")),"where Col1 is not null ",0)))
Functions used:
QUERY
INDEX
TRANSPOSE
IF
LEN
SPLIT
REGEXREPLACE
If you only need to do this for one cell (or you have your heart set on dragging the formula down into individual cells), use the following formula:
=REGEXEXTRACT(" "&N2&" ","\s(\d{8})\s")
However, I suspect you want to process the eight-digit number out of all cells running N2:N. If that is the case, clear whatever will be your results column (including any headers) and place the following in the top cell of that otherwise cleared results column:
=ArrayFormula({"Your Header"; IF(N2:N="",,IFERROR(REGEXEXTRACT(" "&N2:N&" ","\s(\d{8})\s")))})
Replace the header text Your Header with whatever you want your actual header text to be. The formula will show that header text and will return all results for all rows where N2:N is not null. Where no eight-digit number is found, null will be returned.
By prepending and appending a space to the N2:N raw strings before processing, spaces before and after string components can be used to determine where only eight digits exist together (as opposed to eight digits within a longer string of digits).
The only assumption here is that there are, in fact, spaces between string components. I did not assume that the eight-digit number will always be in a certain position (e.g., first, last) within the string.
Try this, take a look at Example sheet
=FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8)
Or this to get them all.
=JOIN(" ,",FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8))
Explanation
SPLIT with the dilimiter set to " " space TRANSPOSE and FILTER TRANSPOSE(SPLIT(B2," ") with the condition1 set to LEN(TRANSPOSE(SPLIT(B2," "))) is = 8
JOIN the outputed column whith " ," to gat all occurrences of number with a length of 8
Note: to get the numbers with the length of N just replace 8 in the FILTER function with a cell refrence.
Using this on a cell worked just fine for me:
(cell_with_data)=REGEXEXTRACT(A1,"[0-9]{8}$")

How count an variable's frequency in specific column in sas

I would like to creare a variable along with each subject id, variable is ci_em_ti = COUNT “Impaired” values among the following variables: bvmdrt_cutoff, craftivmmt_cutoff, craftpimmt_cutoff, craftvdelt_cutoff, craftpdelt_cutoff, nlairt_cutoff, nlsdt_cutoff, nlldt_cutoff
How should I do this in SAS?
I tried
countc(cats(of bvmdrt_cutoff, craftivmmt_cutoff, craftpimmt_cutoff, craftvdelt_cutoff, craftpdelt_cutoff, nlairt_cutoff, nlsdt_cutoff), "Impaired")`
but it done not work
The function COUNTC() counts the number of times any of the listed characters appear. By searching for Impaired you are searching for the characters: adeiImpr. So one value of "Missing" will contribute 2 into the count since it has two lowercase i's and "Normal" will count as 3 because the letters r,m and a. "Imparied" will count as 8 since all of the characters are in the search list.
The function COUNT() will search for the number of times a substring occurs so you might try that.
Are you sure your values are character strings? If instead they are numbers with a user defined format attached the CATS() function will not use the formatted values. So you will need to search for the codes instead of the decodes.
PS There is no need to add the OF keyword when there is only one variable in the list. Either remove the OF or remove the commas.
You say count in a column but then your function is actually counting for several columns but a single row. Since you haven't provided usable data, I'll use SASHELP.HEART instead.
This shows how to display your values in each column.
proc freq data=sashelp.heart;
table chol_status bp_status weight_status smoking_status;
run;

Move next available column value to previous available column space in informatica

0
votes
1 view
Hi,
I have a scenario, where in we have a single record and multiple columns like this
Record_number cd1 cd2 cd3 cd4 cd5 cd6 cd7 cd8 cd9
Here are values for the for the above record
123 12 null 13 14 null 15 16 17 null
Here we have value for cd1 and not for cd2 and we have value for cd3 so cd2 is empty so cd3 should get into cd2 since it was empty so we should move the next available values to previous available spaces.
Does anyone know how to achieve this scenario?
If I understand your question correctly, this can be easily done using an expression transformation.
First create a variable port that would concatenate all the non-null values using some separator, e.g.|, like:
IIF(ISNULL(cd1),'',cd1 || '|') ||
IIF(ISNULL(cd2),'',cd2 || '|') ||
...
IIF(ISNULL(cd9),'',cd9 || '|') ||
This should result in pipe delimited list with the nulls removed, e.g.:
123|12|13|14|15|16|17|
Next create an output port for each column, that would get the correct substring using index of the separator. I'll leave coding this part to you, but if you'd have issues, please let me know.
One approach could be to use an expression transformation as follows:
First concatenate all the ports in a single field using a delimiter (for example ',')
v_CONCAT:= cd1||','||cd2||','||cd3||','||cd4||','||cd5||','||cd6||','||cd7||','||cd8||','||cd9
Now create the output ports using regular expressions
o_cd1:=REG_EXTRACT(v_CONCAT,',*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*)',1)
o_cd2:=REG_EXTRACT(v_CONCAT,',*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*)',2)
o_cd3:=REG_EXTRACT(v_CONCAT,',*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*)',3)
.
.
and so on.
REG_EXTRACT extracts a substring from the input string that matches the regular expression.
() - a group. There will be as many groups as your ports cd1-cd12
,* - zero or more commas, if a value is null two commas will appear consecutively
[^,] - anything other than comma
[^,]* - zero or more of any character other than comma
The third parameter to REG_EXTRACT denotes which group you want as output. For o_cd1 we want the first non-NULL value, so it is 1 and for o_cd2, it is 2 and so on

extract number from string in Oracle

I am trying to extract a specific text from an Outlook subject line. This is required to calculate turn around time for each order entered in SAP. I have a subject line as below
SO# 3032641559 FW: Attached new PO 4500958640- 13563 TYCO LJ
My final output should be like this: 3032641559
I have been able to do this in MS excel with the formulas like this
=IFERROR(INT(MID([#[Normalized_Subject]],SEARCH(30,[#[Normalized_Subject]]),10)),"Not Found")
in the above formula [#[Normalized_Subject]] is the name of column in which the SO number exists. I have asked to do this in oracle but I am very new to this. Your help on this would be greatly appreciated.
Note: in the above subject line the number 30 is common in every subject line.
The last parameter of REGEXP_SUBSTR() indicates the sub-expression you want to pick. In this case you can't just match 30 then some more numbers as the second set of digits might have a 30. So, it's safer to match the following, where x are more digits.
SO# 30xxxxxx
As a regular expression this becomes:
SO#\s30\d+
where \s indicates a space \d indicates a numeric character and the + that you want to match as many as there are. But, we can use the sub-expression substringing available; in order to do that you need to have sub-expressions; i.e. create groups where you want to split the string:
(SO#\s)(30\d+)
Put this in the function call and you have it:
regexp_substr(str, '(SO#\s)(30\d+)', 1, 1, 'i', 2)
SQL Fiddle

How to keep leading zero and add comma in openoffice calc formula?

I have 6 fields in a row in open office, the 1st is a word, the 2nd, 3rd, and 4th are a number with a leading zero, the 5th and 6th are regular numbers. How do I join them all together with a comma between them so that the leading zero stays?
Based on your comment about your numbers having a leading 0 in virtue of a custom number format, you need to incorporate TEXT() functions into your formula to retain (i.e., add) your leading 0s.
=CONCATENATE(A1,",",TEXT(B1,"0#####"),",",TEXT(C1,"0#####"),",",TEXT(D1,"0#####"),",",E1,",",F1)
Just be sure to include as many #'s as the max length of a number in that field.
Please try:
=A1&",0"&B1&",0"&C1&",0"&D1&","&E1&","&F1