How to output SAS IML values for printing - printing

I would like to take values that are calculated in IML to be used in SAS' printing functionality %PRNTINIT. This functionality is used to provide weekly reports from a database that can get updated.
I have some legacy code that uses proc sql to declare macro-type values that are called upon later, e.g.:
Declaring variables: tot1-tot4
*Get total number of subjects in each group in macro variable;
proc sort data = avg3; by description; run;
proc sql noprint;
select _freq_
into: tot1-:tot4
from avg3;
quit;
Calling variables tot1-tot4 for printing
%print(column = 1, style = bold, just = center, lines = bottom:none);
%print("(N= &tot1)", column = 2, just = center, lines = bottom:none);
%print("(N= &tot2)", column = 3, just = center, lines = bottom:none);
%print("(N= &tot3)", column = 4, just = center, lines = bottom:none);
%print("(N= &tot4 )", column = 5, just = center, lines = bottom:none);
%print(column = 6, just = center, lines = bottom:none);
I would like to be able to call values from IML similarly, if possible.
Example data:
data test ;
input age type gender $;
cards;
1 1 m
1 1 m
1 1 m
1 1 f
1 1 f
1 2 f
2 1 m
2 1 f
2 2 m
2 2 m
2 2 m
2 2 m
2 2 m
2 2 f
2 2 f
2 2 f
;
proc freq data = test;
tables type*age / chisq norow nocol nopercent outexpect out=out1 ;
tables type*gender / chisq norow nocol nopercent outexpect out=out2 ;
run;
options missing=" ";
proc iml;
reset print;
use out2;
read all var {count} into count;
type1 = count[1:2] ;
type2 = count[3:4] ;
tab = type1 || type2 ;
cols = tab[+,] ;
rows = tab[,+] ;
tot = sum(tab) ;
perc = round(cols / tot, .01) ;
cell_perc = round(tab / (cols//cols) , .01) ;
expect = (rows * cols) / tot ;
chi_1 = sum((tab - expect)##2/expect) ;
p_chi_1 = 1-CDF('CHISQUARE',chi_1, ((ncol(tab)-1)*(nrow(tab)-1)));
print tab p_chi_1 perc cell_perc;
out_sex = tab || (. // p_chi_1);
print out_sex;
print out_sex[colname={"1","2"}
rowname={"f" "m" "p-value"}
label="Table of Type by Gender"];
call symput(t1_sum, cols[1,1]) ;
%let t2_sum = put(cols[1,2]) ;
%let t1_per = perc[1,1] ;
%let t2_per = perc[1,2] ;
%let t1_f = tab[1,1] ;
%let t1_m = tab[2,1] ;
%let t2_f = tab[1,2] ;
%let t2_m = tab[2,2] ;
%let t1_f_p = cell_perc[1,1] ;
%let t1_m_p = cell_perc[2,1] ;
%let t2_f_p = cell_perc[1,2] ;
%let t2_m_p = cell_perc[2,2] ;
%let p_val = p_chi_1 ;
***** is it possible to list output values here for use in table building ??? ;
* like: %let t1_f = tab[1,1]
%let t2_f = tab[2,1] etc... ;
quit;
So I would like to declare a print statement like the following:
%print( "(N=&tab[1,1], column = 1, just=center, lines = bottom:none);
%print( "(N=&tab[1,2], column = 2, just=center, lines = bottom:none);
etc...
Any help on this is greatly appreciated...
Update: Unable to extract declared macro values out of IML
I have been able to calculate the correct values and format the table successfully.
However, I am unable to extract the values for use in the print macro.
I have created some matrices and calculated values in IML, but when I try to declare macro variables for use later, the only thing that is returned is the literal value that I declared the variable to be... e.g.:
and
You can see in the table what I want the numbers to be, but have thus far been unsuccessful. I have tried using %let, put, symput , and symputx without success.
call symput(t1_sum, cols[1,1]) ;
%let t2_sum = put(cols[1,2]) ;
%let t1_per = perc[1,1] ;
%let t2_per = perc[1,2] ;
%let t1_f = tab[1,1] ;
%let t1_m = tab[2,1] ;
%let t2_f = tab[1,2] ;
%let t2_m = tab[2,2] ;
%let t1_f_p = cell_perc[1,1] ;
%let t1_m_p = cell_perc[2,1] ;
%let t2_f_p = cell_perc[1,2] ;
%let t2_m_p = cell_perc[2,2] ;
Blerg...

A SAS/IML matrix must be all numeric or all character, which is why your attempt did not work. However, the SAS/IML PRINT statement has several options that enable you to label columns and rows and to apply formats. See http://blogs.sas.com/content/iml/2011/08/01/options-for-printing-a-matrix/
Together with the global SAS OPTIONS statement, I think you can get the output that you want.
1) Use the global statement
options missing=" ";
to tell SAS to print missing values as blanks.
2) Your goal is to append a column to the 2x2 TAB matrix. You can use (numeric) missing values for the rows that have no data:
out_age = tab || (. // p_chi_1);
3) You can now print this 2x3 table, and use the COLNAME= and ROWNAME= options to display row headings:
print out_age[rowname={"1","2"}
colname={"f" "m" "p-value"}
label="Table of Type by Gender"];
If you really want to use your old-style macro, you can use the SYMPUTX statement to copy values from SAS/IML into macro variables, as shown in this article: http://blogs.sas.com/content/iml/2011/10/17/does-symput-work-in-iml/

After much searching, and finding some help here on SO, I was able to piece the answer together.
The output value has to be a string
The name of the macro variable has to be in quotes
The call has to be to symputx in order to trim extra whitespace (when compared to symput)
Code to extract IML values to macro variables
call symputx('t1_sum', char(cols[1,1])) ;
call symputx('t2_sum', char(cols[1,2])) ;
call symputx('t1_per', char(perc[1,1])) ;
call symputx('t2_per', char(perc[1,2])) ;
call symputx('t1_f' , char(tab[1,1])) ;
call symputx('t1_m' , char(tab[2,1])) ;
call symputx('t2_f' , char(tab[1,2])) ;
call symputx('t2_m' , char(tab[2,2])) ;
call symputx('t1_f_p' , char(cell_perc[1,1])) ;
call symputx('t1_m_p' , char(cell_perc[2,1])) ;
call symputx('t2_f_p' , char(cell_perc[1,2])) ;
call symputx('t2_m_p' , char(cell_perc[2,2])) ;
call symputx('p_val' , char(round(p_chi_1, .001))) ;
Partial code used to build table using old SAS %PRNTINIT macro
...
%print("Female", column = 1, just = center );
%print("&t1_f (&t1_f_p)", column = 2, just = center );
%print("&t2_f (&t2_f_p)", column = 3, just = center );
%print(, column = 4, just = center );
%print(proc = newrow);
%print("Male", column = 1, just = center );
%print("&t1_m (&t1_m_p)", column = 2, just = center );
%print("&t2_m (&t2_m_p)", column = 3, just = center );
%print("&p_val", column = 4, just = center );
...
The desired result:

Related

add value afterwards to key in table lua

Does someone know how to add an value to an key which already has an value ?
for example:
x = {}
x[1] = {string = "hallo"}
x[1] = {number = 10}
print(x[1].string) --nil
print(x[1].number) --10
It should be possible to print both things out. The same way how it is here possible:
x[1] = { string = "hallo" ; number = 10}
I just need to add some informations afterwards to the table and especially to the same key.
Thanks!
x = {} -- create an empty table
x[1] = {string = "hallo"} -- assign a table with 1 element to x[1]
x[1] = {number = 10} -- assign another table to x[1]
The second assignment overwrites the first assignment.
x[1]["number"] = 10 or short x[1].number = 10 will add a field number with value 10 to the table x[1]
Notice that your x[1] = { string = "hallo" ; number = 10} is acutally equivalent to
x[1] = {}
x[1]["string"] = "hallo"
x[1]["number"] = 10

pass a while loop in Tsql / multiple values for one variable to exec proc

I've been trying to resolve this since a while, still couldn't figure out how to apply a while value like:
while ....(having values in (X1, X2, X3, ........)
(
execute 'package....'
Param = X
)
passing every time the one of the values of X, X1 then X2 and so on.
You can pass all params to temporary table and then loop them using WHILE:
CREATE TABLE #tab(id INT IDENTITY(1,1), param_value NVARCHAR(MAX));
INSERT INTO #tab(param_value)
VALUES (#X1), (#X2), (#X3); -- ...
DECLARE #counter INT = 1,
#param NVARCHAR(MAX);
WHILE #counter <= (SELECT MAX(id) FROM #tab)
BEGIN
SELECT #param = param_value
FROM #tab
WHERE id = #counter;
EXEC [dbo].[my_stored_proc]
#param;
SET #counter += 1;
END
SqlFiddleDemo

How can I better parse variable time stamp information in Fortran?

I am writing code in gfortran to separate a variable time stamp into its separate parts of year, month, and day. I have written this code so the user can input what the time stamp format will be (ie. YEAR/MON/DAY, DAY/MON/YEAR, etc). This creates a total of 6 possible combinations. I have written code that attempts to deal with this, but I believe it to be ugly and poorly done.
My current code uses a slew of 'if' and 'goto' statements. The user provides 'tsfo', the time stamp format. 'ts' is a character array containing the time stamp data (as many as 100,000 time stamps). 'tsdelim' is the delimiter between the year, month, and day. I must loop from 'frd' (the first time stamp) to 'nlines' (the last time stamp).
Here is the relevant code.
* Choose which case to go to.
first = INDEX(tsfo,tsdelim)
second = INDEX(tsfo(first+1:),tsdelim) + first
if (INDEX(tsfo(1:first-1),'YYYY') .ne. 0) THEN
if (INDEX(tsfo(first+1:second-1),'MM') .ne. 0) THEN
goto 1001
else
goto 1002
end if
else if (INDEX(tsfo(1:first-1),'MM') .ne. 0) THEN
if (INDEX(tsfo(first+1:second-1),'DD') .ne. 0) THEN
goto 1003
else
goto 1004
end if
else if (INDEX(tsfo(1:first-1),'DD') .ne. 0) THEN
if (INDEX(tsfo(first+1:second-1),'MM') .ne. 0) THEN
goto 1005
else
goto 1006
end if
end if
first = 0
second = 0
* Obtain the Julian Day number of each data entry.
* Acquire the year, month, and day of the time stamp.
* Find 'first' and 'second' and act accordingly.
* Case 1: YYYY/MM/DD
1001 do i = frd,nlines
first = INDEX(ts(i),tsdelim)
second = INDEX(ts(i)(first+1:),tsdelim) + first
read (ts(i)(1:first-1), '(i4)') Y
read (ts(i)(first+1:second-1), '(i2)') M
read (ts(i)(second+1:second+2), '(i2)') D
* Calculate the Julian Day number using a function.
temp1(i) = JLDYNUM(Y,M,D)
end do
goto 1200
* Case 2: YYYY/DD/MM
1002 do i = frd,nlines
first = INDEX(ts(i),tsdelim)
second = INDEX(ts(i)(first+1:),tsdelim) + first
read (ts(i)(1:first-1), '(i4)') Y
read (ts(i)(second+1:second+2), '(i2)') M
read (ts(i)(first+1:second-1), '(i2)') D
* Calculate the Julian Day number using a function.
temp1(i) = JLDYNUM(Y,M,D)
end do
goto 1200
* Onto the next part of the code
1200 blah blah blah
I believe this code will work, but I do not think it is a very good method. Is there a better way to go about this?
It is important to note that the indices 'first' and 'second' must be calculated for each time stamp as the month and day can both be represented by 1 or 2 integers. The year is always represented by 4.
With only six permutations to handle I would just build a look-up table with the whole tsfo string as the key and the positions of year, month and day (1st, 2nd or 3rd) as the values. Any unsupported formats should produce an error, which I haven't coded below. When subsequently you loop though your ts list and split an item you know which positions to cast to the year, month and day integer variables:
PROGRAM timestamp
IMPLICIT NONE
CHARACTER(len=10) :: ts1(3) = ["2000/3/4 ","2000/25/12","2000/31/07"]
CHARACTER(len=10) :: ts2(3) = ["3/4/2000 ","25/12/2000","31/07/2000"]
CALL parse("YYYY/DD/MM",ts1)
print*
CALL parse("DD/MM/YYYY",ts2)
CONTAINS
SUBROUTINE parse(tsfo,ts)
IMPLICIT NONE
CHARACTER(len=*),INTENT(in) :: tsfo, ts(:)
TYPE sti
CHARACTER(len=10) :: stamp = "1234567890"
INTEGER :: iy = -1, im = -1, id = -1
END TYPE sti
TYPE(sti),PARAMETER :: stamps(6) = [sti("YYYY/MM/DD",1,2,3), sti("YYYY/DD/MM",1,3,2),&
sti("MM/DD/YYYY",2,3,1), sti("DD/MM/YYYY",3,2,1),&
sti("MM/YYYY/DD",2,1,3), sti("DD/YYYY/MM",3,1,2)]
TYPE(sti) :: thisTsfo
INTEGER :: k, k1, k2
INTEGER :: y, m, d
CHARACTER(len=10) :: cc(3)
DO k=1,SIZE(stamps)
IF(TRIM(tsfo) == stamps(k)%stamp) THEN
thisTsfo = stamps(k)
EXIT
ENDIF
ENDDO
print*,thisTsfo
DO k=1,SIZE(ts)
k1 = INDEX(ts(k),"/")
k2 = INDEX(ts(k),"/",BACK=.TRUE.)
cc(1) = ts(k)(:k1-1)
cc(2) = ts(k)(k1+1:k2-1)
cc(3) = ts(k)(k2+1:)
READ(cc(thisTsfo%iy),'(i4)') y
READ(cc(thisTsfo%im),'(i2)') m
READ(cc(thisTsfo%id),'(i2)') d
PRINT*,ts(k),y,m,d
ENDDO
END SUBROUTINE parse
END PROGRAM timestamp
I would encode the different cases in another way, like this:
module foo
implicit none
private
public encode_datecode
contains
integer function encode_datecode(datestr, sep)
character(len=*), intent(in) :: datestr, sep
integer :: first, second
character(len=1) :: c1, c2, c3
first = index(datestr, sep)
second = index(datestr(first+1:), sep) + first
c1 = datestr(1:1)
c2 = datestr(first+1:first+1)
c3 = datestr(second+1:second+1)
foo = num(c1) + 3*num(c2) + 9*num(c3)
end function encode_datecode
integer function num(c)
character(len=1) :: c
if (c == 'Y') then
num = 0
else if (c == 'M') then
num = 1
else if (c == 'D') then
num = 2
else
stop "Illegal character"
end if
end function num
end module foo
and then handle the legal cases (21, 15, 19, 7, 11, 5) in a SELECT statement.
This takes advantage of the fact that there won't be a 'YDDY/MY/YM' format.
If you prefer better binary or decimal readability, you can also multiply by four or by 10 instead of 3.

Parsing a TeX-like language with lpeg

I am struggling to get my head around LPEG. I have managed to produce one grammar which does what I want, but I have been beating my head against this one and not getting far. The idea is to parse a document which is a simplified form of TeX. I want to split a document into:
Environments, which are \begin{cmd} and \end{cmd} pairs.
Commands which can either take an argument like so: \foo{bar} or can be bare: \foo.
Both environments and commands can have parameters like so: \command[color=green,background=blue]{content}.
Other stuff.
I also would like to keep track of line number information for error handling purposes. Here's what I have so far:
lpeg = require("lpeg")
lpeg.locale(lpeg)
-- Assume a lot of "X = lpeg.X" here.
-- Line number handling from http://lua-users.org/lists/lua-l/2011-05/msg00607.html
-- with additional print statements to check they are working.
local newline = P"\r"^-1 * "\n" / function (a) print("New"); end
local incrementline = Cg( Cb"linenum" )/ function ( a ) print("NL"); return a + 1 end , "linenum"
local setup = Cg ( Cc ( 1) , "linenum" )
nl = newline * incrementline
space = nl + lpeg.space
-- Taken from "Name-value lists" in http://www.inf.puc-rio.br/~roberto/lpeg/
local identifier = (R("AZ") + R("az") + P("_") + R("09"))^1
local sep = lpeg.S(",;") * space^0
local value = (1-lpeg.S(",;]"))^1
local pair = lpeg.Cg(C(identifier) * space ^0 * "=" * space ^0 * C(value)) * sep^-1
local list = lpeg.Cf(lpeg.Ct("") * pair^0, rawset)
local parameters = (P("[") * list * P("]")) ^-1
-- And the rest is mine
anything = C( (space^1 + (1-lpeg.S("\\{}")) )^1) * Cb("linenum") / function (a,b) return { text = a, line = b } end
begin_environment = P("\\begin") * Ct(parameters) * P("{") * Cg(identifier, "environment") * Cb("environment") * P("}") / function (a,b) return { params = a[1], environment = b } end
end_environment = P("\\end{") * Cg(identifier) * P("}")
texlike = lpeg.P{
"document";
document = setup * V("stuff") * -1,
stuff = Cg(V"environment" + anything + V"bracketed_stuff" + V"command_with" + V"command_without")^0,
bracketed_stuff = P"{" * V"stuff" * P"}" / function (a) return a end,
command_with =((P("\\") * Cg(identifier) * Ct(parameters) * Ct(V"bracketed_stuff"))-P("\\end{")) / function (i,p,n) return { command = i, parameters = p, nodes = n } end,
command_without = (( P("\\") * Cg(identifier) * Ct(parameters) )-P("\\end{")) / function (i,p) return { command = i, parameters = p } end,
environment = Cg(begin_environment * Ct(V("stuff")) * end_environment) / function (b,stuff, e) return { b = b, stuff = stuff, e = e} end
}
It almost works!
> texlike:match("\\foo[one=two]thing\\bar")
{
command = "foo",
parameters = {
{
one = "two",
},
},
}
{
line = 1,
text = "thing",
}
{
command = "bar",
parameters = {
},
}
But! First, I can't get the line number handling part to work at all. The function within incrementline is never fired.
I also can't quite work out how nested capture information is passed to handling functions (which is why I have scattered Cg, C and Ct semirandomly over the grammar). This means that only one item is returned from within a command_with:
> texlike:match("\\foo{text \\command moretext}")
{
command = "foo",
nodes = {
{
line = 1,
text = "text ",
},
},
parameters = {
},
}
I would also love to be able to check that the environment start and ends match up but when I tried to do so, my back references from "begin" were not in scope by the time I got to "end". I don't know where to go from here.
Late answer but hopefully it'll offer some insight if you're still looking for a solution or wondering what the problem was.
There are a couple of issues with your grammar, some of which can be tricky to spot.
Your line increment here looks incorrect:
local incrementline = Cg( Cb"linenum" ) /
function ( a ) print("NL"); return a + 1 end,
"linenum"
It looks like you meant to create a named capture group and not an anonymous group. The backcapture linenum is essentially being used like a variable. The problem is because this is inside an anonymous capture, linenum will not update properly -- function(a) will always receive 1 when called. You need to move the closing ) to the end so "linenum" is included:
local incrementline = Cg( Cb"linenum" /
function ( a ) print("NL"); return a + 1 end,
"linenum")
Relevant LPeg documentation for Cg capture.
The second problem is with your anything non-terminal rule:
anything = C( (space^1 + (1-lpeg.S("\\{}")) )^1) * Cb("linenum") ...
There are several things to be careful here. First, a named Cg capture (from incrementline rule once it's fixed) doesn't produce anything unless it's in a table or you backref it. The second major thing is that it has an adhoc scope like a variable. More precisely, its scope ends once you close it in an outer capture -- like what you're doing here:
C( (space^1 + (...) )^1)
Which means by the time you reference its backcapture with * Cb("linenum"), that's already too late -- the linenum you really want already closed its scope.
I always found LPeg's re syntax a bit easier to grok so I've rewritten the grammar with that instead:
local grammar_cb =
{
fold = pairfold,
resetlinenum = resetlinenum,
incrementlinenum = incrementlinenum, getlinenum = getlinenum,
error = error
}
local texlike_grammar = re.compile(
[[
document <- '' -> resetlinenum {| docpiece* |} !.
docpiece <- {| envcmd |} / {| cmd |} / multiline
beginslash <- cmdslash 'begin'
endslash <- cmdslash 'end'
envcmd <- beginslash paramblock? {:beginenv: envblock :} (!endslash docpiece)*
endslash openbrace {:endenv: =beginenv :} closebrace / &beginslash {} -> error .
envblock <- openbrace key closebrace
cmd <- cmdslash {:command: identifier :} (paramblock? cmdblock)?
cmdblock <- openbrace {:nodes: {| docpiece* |} :} closebrace
paramblock <- opensq ( {:parameters: {| parampairs |} -> fold :} / whitesp) closesq
parampairs <- parampair (sep parampair)*
parampair <- key assign value
key <- whitesp { identifier }
value <- whitesp { [^],;%s]+ }
multiline <- (nl? text)+
text <- {| {:text: (!cmd !closebrace !%nl [_%w%p%s])+ :} {:line: '' -> getlinenum :} |}
identifier <- [_%w]+
cmdslash <- whitesp '\'
assign <- whitesp '='
sep <- whitesp ','
openbrace <- whitesp '{'
closebrace <- whitesp '}'
opensq <- whitesp '['
closesq <- whitesp ']'
nl <- {%nl+} -> incrementlinenum
whitesp <- (nl / %s)*
]], grammar_cb)
The callback functions are straight-forwardly defined as:
local function pairfold(...)
local t, kv = {}, ...
if #kv % 2 == 1 then return ... end
for i = #kv, 2, -2 do
t[ kv[i - 1] ] = kv[i]
end
return t
end
local incrementlinenum, getlinenum, resetlinenum do
local line = 1
function incrementlinenum(nl)
assert(not nl:match "%S")
line = line + #nl
end
function getlinenum() return line end
function resetlinenum() line = 1 end
end
Testing the grammar with a non-trivial tex-like str with multiple lines:
local test1 = [[\foo{text \bar[color = red, background = black]{
moretext \baz{
even
more text} }
this time skipping multiple
lines even, such wow!}]]
Produces the follow AST in lua-table format:
{
command = "foo",
nodes = {
{
text = "text",
line = 1
},
{
parameters = {
color = "red",
background = "black"
},
command = "bar",
nodes = {
{
text = " moretext",
line = 2
},
{
command = "baz",
nodes = {
{
text = "even ",
line = 3
},
{
text = "more text",
line = 4
}
}
}
}
},
{
text = "this time skipping multiple",
line = 7
},
{
text = "lines even, such wow!",
line = 9
}
}
}
And a second test for begin/end environments:
local test2 = [[\begin[p1
=apple,
p2=blue]{scope} scope foobar
\end{scope} global foobar]]
Which seems to give approximately what you're looking for:
{
{
{
text = " scope foobar",
line = 3
},
parameters = {
p1 = "apple",
p2 = "blue"
},
beginenv = "scope",
endenv = "scope"
},
{
text = " global foobar",
line = 4
}
}

Passing comma separated value as an IN parameter in stored procedure

I am new to DB2 queries.
Here, I am passing a comma separated value as an IN parameter in a Stored Procedure. I want to search on the basis of those values.
Select * from USER where user_id in (IN_User);
Here, IN_User will have values of the kind ('val1','val2','val3')
It should return all the rows which has val1 or val2 or val3 as the User_id. As much as I know this can be done using UDF but I want to know is there any other way to do it without UDF.
please create a function to split the comma separated string
Please see the below function
CREATE FUNCTION StringToRows(
cString1 CLOB (10 M) ,
cStringSplitting1 VARCHAR(10) )
RETURNS TABLE (Lines VARCHAR(500))
SPECIFIC StringToRows_Big
DETERMINISTIC
NO EXTERNAL ACTION
CONTAINS SQL
BEGIN ATOMIC
DECLARE cStringSplitting VARCHAR(10);
DECLARE LenSplit SMALLINT;
SET cStringSplitting = cStringSplitting1;
SET LenSplit = LENGTH(cStringSplitting);
IF LENGTH(TRIM(cStringSplitting)) = 0 THEN
SET cStringSplitting = ' ', LenSplit = 1 ;
END IF ;
RETURN WITH
TEMP1 ( STRING) as (values (cString1) ),
TEMP2 ( Lines, STRING_left) as
(SELECT
SUBSTR(STRING,1, CASE WHEN LOCATE(cStringSplitting, STRING) = 0 THEN LENGTH(STRING) ELSE LOCATE(cStringSplitting,STRING) - 1 END),
(CASE WHEN (LOCATE(cStringSplitting, STRING) = 0) THEN '' ELSE SUBSTR(STRING, LOCATE(cStringSplitting,STRING) + LenSplit) END)
FROM TEMP1 WHERE LENGTH(STRING) > 0
UNION ALL
SELECT
SUBSTR(STRING_left,1, CASE LOCATE(cStringSplitting,STRING_left) WHEN 0 THEN LENGTH(STRING_left) ELSE LOCATE(cStringSplitting,STRING_left) - 1 END),
(CASE WHEN LOCATE(cStringSplitting,STRING_left) = 0 THEN '' ELSE SUBSTR(STRING_left, LOCATE(cStringSplitting,STRING_left) + LenSplit) END)
FROM TEMP2 WHERE LENGTH(STRING_left) > 0 )
SELECT Lines FROM TEMP2;
END
please see the sample stored procedure to call the function
CREATE PROCEDURE TEST_USR(IN #inputParam CLOB (10 M))
SPECIFIC TEST_USR
DYNAMIC RESULT SETS 1
P1: BEGIN
DECLARE CURSOR1 CURSOR WITH RETURN FOR
Select * from USER where user_id IN (SELECT * FROM TABLE(StringToRows(#inputParam, ',')) AS test);
OPEN CURSOR1;
END P1

Resources