Well, that led through an interesting excursion in the help file. I had either forgotten about or never knew about the CATQ function and the family of "Excel" functions whose names end with "_slk" (I assume the suffix comes from the late lamented PROC SYLK).
I started looking at function help because I did remember the existence of the VVALUE function, but not all of the details. I was thinking that would be useful for formatting values, but it turns out that VVALUE works only inside a data step, or at least it is documented to work only in a data step. But you could use VVALUE to good effect with your function in a data step.
I would propose a different syntax for the new function, where you provide arguments in pairs of (value, value-options); you could provide separate options for every input value, which would allow the values to have different formats, quote some arguments but not others, and so forth. So the function would be something like
result = catall(delimiter, value1, options1, value2, options2, ...);
and an example usage would be
mynewvalue = catall(delimiter, id_num, 'FS', birth_date, 'f=date11.',
name, 'q');
You're right, this would probably have to be provided as a built-in function by SAS, because some of the parameters could be numeric, and because to be most useful it would have to be callable from PROC SQL (which doesn't accept array arguments).
Hmm. PROC SQL seems to have a length limit of 200 characters for the value returned by some but not all functions, which makes many character functions less useful than they might be. I wonder why that might be, or if there is a workaround.
%let longval = %sysfunc(repeat(*, 400));
%let longlen = %length(&LONGVAL.);
%put &=LONGLEN;
proc sql;
create table temp
(
longval1 char(401),
longval2 char(401) ,
longval3 char(401) ,
name char(10)
);
insert into temp
select
repeat('*', 400) length=401 ,
"&LONGVAL." length=401,
upcase("&LONGVAL.") length=401 ,
name
from
sashelp.class
where
name='Alfred';
select
(length(longval1)) as longlen1 , /* 200 */
(length(longval2)) as longlen2 , /* 401 */
(length(longval3)) as longlen3 /* 401 */
from
temp;
quit;
... View more