mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 15:40:05 +00:00
feat(*): recreate library as scoped package
This commit is contained in:
46
base/mf_getquotedstr.sas
Executable file
46
base/mf_getquotedstr.sas
Executable file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
@file
|
||||
@brief Adds custom quotes / delimiters to a delimited string
|
||||
@details Can be used in open code, eg as follows:
|
||||
|
||||
%put %mf_getquotedstr(blah blah blah);
|
||||
|
||||
which returns:
|
||||
> 'blah','blah','blah'
|
||||
|
||||
@param in_str the unquoted, spaced delimited string to transform
|
||||
@param dlm= the delimeter to be applied to the output (default comma)
|
||||
@param indlm= the delimeter used for the input (default is space)
|
||||
@param quote= the quote mark to apply (S=Single, D=Double). If any other value
|
||||
than uppercase S or D is supplied, then that value will be used as the
|
||||
quoting character.
|
||||
@return output returns a string with the newly quoted / delimited output.
|
||||
|
||||
@version 9.2
|
||||
@author Allan Bowe
|
||||
**/
|
||||
|
||||
|
||||
%macro mf_getquotedstr(IN_STR,DLM=%str(,),QUOTE=S,indlm=%str( )
|
||||
)/*/STORE SOURCE*/;
|
||||
%if "e=S %then %let quote=%str(%');
|
||||
%else %if "e=D %then %let quote=%str(%");
|
||||
%else %let quote=%str();
|
||||
%local i item buffer;
|
||||
%let i=1;
|
||||
%do %while (%qscan(&IN_STR,&i,%str(&indlm)) ne %str() ) ;
|
||||
%let item=%qscan(&IN_STR,&i,%str(&indlm));
|
||||
%if %bquote("E) ne %then %let item="E%qtrim(&item)"E;
|
||||
%else %let item=%qtrim(&item);
|
||||
|
||||
%if (&i = 1) %then %let buffer =%qtrim(&item);
|
||||
%else %let buffer =&buffer&DLM%qtrim(&item);
|
||||
|
||||
%let i = %eval(&i+1);
|
||||
%end;
|
||||
|
||||
%let buffer=%sysfunc(coalescec(%qtrim(&buffer),"E"E));
|
||||
|
||||
&buffer
|
||||
|
||||
%mend;
|
||||
Reference in New Issue
Block a user