From c7a0f04ff6b395e33819e0baf765202a053a4ff4 Mon Sep 17 00:00:00 2001 From: Kun Jinkao <45487685+Snoopy1866@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:33:21 +0800 Subject: [PATCH] =?UTF-8?q?perf(cross=5Ftable)=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20`ROWCAT`,=20`COLCAT`=20=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/cross_table/readme.md | 6 +++--- gbk/cross_table.sas | 17 +++++++++-------- utf8/cross_table.sas | 17 +++++++++-------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/cross_table/readme.md b/docs/cross_table/readme.md index 758833e..b0f7d5d 100644 --- a/docs/cross_table/readme.md +++ b/docs/cross_table/readme.md @@ -71,7 +71,7 @@ INDATA = SHKY.ADSL(where = (FAS = "Y")) ```sas ROWCAT = PARSIG -ROWCAT = PARSIG("正常" "异常无临床意义" "异常有临床意义") +ROWCAT = PARSIG("正常", "异常无临床意义", "异常有临床意义") ``` [**Example**](#一般用法) @@ -306,8 +306,8 @@ ROWCAT = PARSIGN(DESCENDING) ```sas %cross_table(indata = analysis1, - rowcat = PARSIG1("正常" "异常无临床意义" "异常有临床意义"), - colcat = PARSIG2("正常" "异常无临床意义" "异常有临床意义")); + rowcat = PARSIG1("正常", "异常无临床意义", "异常有临床意义"), + colcat = PARSIG2("正常", "异常无临床意义", "异常有临床意义")); ``` ![](./assets/example-normal-2.png) diff --git a/gbk/cross_table.sas b/gbk/cross_table.sas index 8f56669..54e9df7 100644 --- a/gbk/cross_table.sas +++ b/gbk/cross_table.sas @@ -5,6 +5,7 @@ Macro Label: Author: wtwang Version Date: 2022-09-21 V1.1 2024-05-28 V1.2 + 2024-06-05 V1.2.1 =================================== */ @@ -92,7 +93,7 @@ Version Date: 2022-09-21 V1.1 %end; %let IS_ROW_CAT_SPECIFIED = FALSE; - %let reg_rowcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:\s+".*")*\s*)?\))?$/); + %let reg_rowcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:[\s,]+".*")*\s*)?\))?$/); %let reg_rowcat_id = %sysfunc(prxparse(®_rowcat)); %if %sysfunc(prxmatch(®_rowcat_id, &rowcat)) = 0 %then %do; %put ERROR: ROWCAT = &rowcat ʽȷ; @@ -111,7 +112,7 @@ Version Date: 2022-09-21 V1.1 %else %do; %if %bquote(&row_val) = %bquote() %then %do; /*δֵָ*/ proc sql noprint; - select distinct cats("""", &row_var, """") into :row_val separated by " " from &indata where not missing(&row_var); + select distinct cats("""", &row_var, """") into :row_val separated by "," from &indata where not missing(&row_var); quit; %end; %else %do; /*ָ˷ֵ*/ @@ -129,7 +130,7 @@ Version Date: 2022-09-21 V1.1 %end; %let IS_COL_CAT_SPECIFIED = FALSE; - %let reg_colcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:\s+".*")*\s*)?\))?$/); + %let reg_colcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:[\s,]+".*")*\s*)?\))?$/); %let reg_colcat_id = %sysfunc(prxparse(®_colcat)); %if %sysfunc(prxmatch(®_colcat_id, &colcat)) = 0 %then %do; %put ERROR: COLCAT = &colcat ʽȷ; @@ -151,7 +152,7 @@ Version Date: 2022-09-21 V1.1 %else %do; %if %bquote(&col_val) = %bquote() %then %do; /*δֵָ*/ proc sql noprint; - select distinct cats("""", &col_var, """") into :col_val separated by " " from &indata where not missing(&col_var); + select distinct cats("""", &col_var, """") into :col_val separated by "," from &indata where not missing(&col_var); quit; %end; %else %do; /*ָ˷ֵ*/ @@ -501,9 +502,9 @@ Version Date: 2022-09-21 V1.1 %end; %else %do; /*ֱֵָrowvalķ*/ - %let row_cat_n = %sysfunc(kcountw(%bquote(&row_val), %bquote( ), q)); + %let row_cat_n = %sysfunc(kcountw(%bquote(&row_val), %bquote(,), qs)); %do i = 1 %to &row_cat_n; - %let row_&i = %sysfunc(kscanx(%bquote(&row_val), &i, %bquote( ), q)); + %let row_&i = %sysfunc(kscanx(%bquote(&row_val), &i, %bquote(,), qs)); %end; %end; @@ -548,9 +549,9 @@ Version Date: 2022-09-21 V1.1 %end; %else %do; /*ֱֵָcolvalķ*/ - %let col_cat_n = %sysfunc(kcountw(%bquote(&col_val), %bquote( ), q)); + %let col_cat_n = %sysfunc(kcountw(%bquote(&col_val), %bquote(,), qs)); %do i = 1 %to &col_cat_n; - %let col_&i = %sysfunc(kscanx(%bquote(&col_val), &i, %bquote( ), q)); + %let col_&i = %sysfunc(kscanx(%bquote(&col_val), &i, %bquote(,), qs)); %end; %end; diff --git a/utf8/cross_table.sas b/utf8/cross_table.sas index 5877f2f..65ac1ab 100644 --- a/utf8/cross_table.sas +++ b/utf8/cross_table.sas @@ -5,6 +5,7 @@ Macro Label:基本列联表 Author: wtwang Version Date: 2022-09-21 V1.1 2024-05-28 V1.2 + 2024-06-05 V1.2.1 =================================== */ @@ -92,7 +93,7 @@ Version Date: 2022-09-21 V1.1 %end; %let IS_ROW_CAT_SPECIFIED = FALSE; - %let reg_rowcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:\s+".*")*\s*)?\))?$/); + %let reg_rowcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:[\s,]+".*")*\s*)?\))?$/); %let reg_rowcat_id = %sysfunc(prxparse(®_rowcat)); %if %sysfunc(prxmatch(®_rowcat_id, &rowcat)) = 0 %then %do; %put ERROR: 参数 ROWCAT = &rowcat 格式不正确!; @@ -111,7 +112,7 @@ Version Date: 2022-09-21 V1.1 %else %do; %if %bquote(&row_val) = %bquote() %then %do; /*未指定分类的值*/ proc sql noprint; - select distinct cats("""", &row_var, """") into :row_val separated by " " from &indata where not missing(&row_var); + select distinct cats("""", &row_var, """") into :row_val separated by "," from &indata where not missing(&row_var); quit; %end; %else %do; /*指定了分类的值*/ @@ -129,7 +130,7 @@ Version Date: 2022-09-21 V1.1 %end; %let IS_COL_CAT_SPECIFIED = FALSE; - %let reg_colcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:\s+".*")*\s*)?\))?$/); + %let reg_colcat = %bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\((\s*".*"(?:[\s,]+".*")*\s*)?\))?$/); %let reg_colcat_id = %sysfunc(prxparse(®_colcat)); %if %sysfunc(prxmatch(®_colcat_id, &colcat)) = 0 %then %do; %put ERROR: 参数 COLCAT = &colcat 格式不正确!; @@ -151,7 +152,7 @@ Version Date: 2022-09-21 V1.1 %else %do; %if %bquote(&col_val) = %bquote() %then %do; /*未指定分类的值*/ proc sql noprint; - select distinct cats("""", &col_var, """") into :col_val separated by " " from &indata where not missing(&col_var); + select distinct cats("""", &col_var, """") into :col_val separated by "," from &indata where not missing(&col_var); quit; %end; %else %do; /*指定了分类的值*/ @@ -501,9 +502,9 @@ Version Date: 2022-09-21 V1.1 %end; %else %do; /*直接指定分类值,拆分rowval的分类*/ - %let row_cat_n = %sysfunc(kcountw(%bquote(&row_val), %bquote( ), q)); + %let row_cat_n = %sysfunc(kcountw(%bquote(&row_val), %bquote(,), qs)); %do i = 1 %to &row_cat_n; - %let row_&i = %sysfunc(kscanx(%bquote(&row_val), &i, %bquote( ), q)); + %let row_&i = %sysfunc(kscanx(%bquote(&row_val), &i, %bquote(,), qs)); %end; %end; @@ -548,9 +549,9 @@ Version Date: 2022-09-21 V1.1 %end; %else %do; /*直接指定分类值,拆分colval的分类*/ - %let col_cat_n = %sysfunc(kcountw(%bquote(&col_val), %bquote( ), q)); + %let col_cat_n = %sysfunc(kcountw(%bquote(&col_val), %bquote(,), qs)); %do i = 1 %to &col_cat_n; - %let col_&i = %sysfunc(kscanx(%bquote(&col_val), &i, %bquote( ), q)); + %let col_&i = %sysfunc(kscanx(%bquote(&col_val), &i, %bquote(,), qs)); %end; %end;