From b13c33cbde5d72b9fa9629a3b106e16163bc32c3 Mon Sep 17 00:00:00 2001 From: munja Date: Mon, 6 Dec 2021 00:12:36 +0000 Subject: [PATCH] fix: using byte codes to tidy up apostrophe logic, and new param for mf_getquotedstr macro --- all.sas | 21 +++++++++++---------- base/mf_getquotedstr.sas | 19 ++++++++++--------- base/mp_sortinplace.sas | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/all.sas b/all.sas index 0b9befd..5562bd0 100644 --- a/all.sas +++ b/all.sas @@ -626,12 +626,12 @@ https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionex for: > "these","words","are","double","quoted" - @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. + @param [in] in_str The unquoted, spaced delimited string to transform + @param [in] dlm= The delimeter to be applied to the output (default comma) + @param [in] indlm= (,) The delimeter used for the input (default is space) + @param [in] quote= (S) The quote mark to apply (S=Single, D=Double, N=None). + 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 @@ -641,9 +641,10 @@ https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionex %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(); + /* credit Rowland Hale - byte34 is double quote, 39 is single quote */ + %if "e=S %then %let quote=%qsysfunc(byte(39)); + %else %if "e=D %then %let quote=%qsysfunc(byte(34)); + %else %if "e=N %then %let quote=; %local i item buffer; %let i=1; %do %while (%qscan(&IN_STR,&i,%str(&indlm)) ne %str() ) ; @@ -7946,7 +7947,7 @@ run; %let tempvw=%mf_getuniquename(prefix=&sysmacroname); proc sql; create view work.&tempvw as select * from &lib..&ds -order by %mf_getquotedstr(&sortkey,quote=%str()); +order by %mf_getquotedstr(&sortkey,quote=N); /* append sorted data */ proc append base=&lib..&tempds2 data=work.&tempvw; diff --git a/base/mf_getquotedstr.sas b/base/mf_getquotedstr.sas index 1a1d855..94deaf8 100755 --- a/base/mf_getquotedstr.sas +++ b/base/mf_getquotedstr.sas @@ -15,12 +15,12 @@ for: > "these","words","are","double","quoted" - @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. + @param [in] in_str The unquoted, spaced delimited string to transform + @param [in] dlm= The delimeter to be applied to the output (default comma) + @param [in] indlm= (,) The delimeter used for the input (default is space) + @param [in] quote= (S) The quote mark to apply (S=Single, D=Double, N=None). + 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 @@ -30,9 +30,10 @@ %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(); + /* credit Rowland Hale - byte34 is double quote, 39 is single quote */ + %if "e=S %then %let quote=%qsysfunc(byte(39)); + %else %if "e=D %then %let quote=%qsysfunc(byte(34)); + %else %if "e=N %then %let quote=; %local i item buffer; %let i=1; %do %while (%qscan(&IN_STR,&i,%str(&indlm)) ne %str() ) ; diff --git a/base/mp_sortinplace.sas b/base/mp_sortinplace.sas index 5f3a899..82d9ba8 100644 --- a/base/mp_sortinplace.sas +++ b/base/mp_sortinplace.sas @@ -89,7 +89,7 @@ run; %let tempvw=%mf_getuniquename(prefix=&sysmacroname); proc sql; create view work.&tempvw as select * from &lib..&ds -order by %mf_getquotedstr(&sortkey,quote=%str()); +order by %mf_getquotedstr(&sortkey,quote=N); /* append sorted data */ proc append base=&lib..&tempds2 data=work.&tempvw;