Skip to content

Commit

Permalink
perf(cross_table) 优化参数 ROWCAT, COLCAT 的调用方式 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snoopy1866 committed Jun 5, 2024
1 parent 6b953ed commit c7a0f04
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs/cross_table/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ INDATA = SHKY.ADSL(where = (FAS = "Y"))

```sas
ROWCAT = PARSIG
ROWCAT = PARSIG("正常" "异常无临床意义" "异常有临床意义")
ROWCAT = PARSIG("正常", "异常无临床意义", "异常有临床意义")
```

[**Example**](#一般用法)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions gbk/cross_table.sas
Original file line number Diff line number Diff line change
Expand Up @@ -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
===================================
*/

Expand Down Expand Up @@ -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(&reg_rowcat));
%if %sysfunc(prxmatch(&reg_rowcat_id, &rowcat)) = 0 %then %do;
%put ERROR: 参数 ROWCAT = &rowcat 格式不正确!;
Expand All @@ -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; /*指定了分类的值*/
Expand All @@ -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(&reg_colcat));
%if %sysfunc(prxmatch(&reg_colcat_id, &colcat)) = 0 %then %do;
%put ERROR: 参数 COLCAT = &colcat 格式不正确!;
Expand All @@ -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; /*指定了分类的值*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
17 changes: 9 additions & 8 deletions utf8/cross_table.sas
Original file line number Diff line number Diff line change
Expand Up @@ -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
===================================
*/

Expand Down Expand Up @@ -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(&reg_rowcat));
%if %sysfunc(prxmatch(&reg_rowcat_id, &rowcat)) = 0 %then %do;
%put ERROR: 参数 ROWCAT = &rowcat 格式不正确!;
Expand All @@ -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; /*指定了分类的值*/
Expand All @@ -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(&reg_colcat));
%if %sysfunc(prxmatch(&reg_colcat_id, &colcat)) = 0 %then %do;
%put ERROR: 参数 COLCAT = &colcat 格式不正确!;
Expand All @@ -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; /*指定了分类的值*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c7a0f04

Please sign in to comment.