Skip to content

Commit

Permalink
fix(qualify_multi, quantify_multi): 参数 GROUP 无法指定分组名称 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snoopy1866 authored Nov 14, 2024
1 parent 336602e commit 669f53e
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 92 deletions.
35 changes: 3 additions & 32 deletions docs/qualify_multi_test/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
- [INDATA](#indata)
- [VAR](#var)
- [GROUP](#group)
- [GROUPBY](#groupby)

### 可选参数

- [GROUPBY](#groupby)
- [BY](#by)
- [UID](#uid)
- [PATTERN](#pattern)
Expand Down Expand Up @@ -46,42 +46,13 @@

### GROUP

**Syntax** : _variable_

指定分组变量。

> [!WARNING]
>
> - 参数 `GROUP` 不允许指定不存在于参数 `INDATA` 指定的数据集中的变量;
> - 参数 `GROUP` 不允许指定数值型变量;
**Usage** :

```sas
GROUP = ARM
```

[**Example**](#一般用法)
用法同 [GROUP](../qualify_multi/readme.md#group)

---

### GROUPBY

**Syntax** : _variable_<(ASC\<ENDING\> | DESC\<ENDING\>)>

指定分组变量的排序变量及排序方向。

> [!WARNING]
>
> - 参数 `GROUPBY` 不允许指定不存在于参数 `INDATA` 指定的数据集中的变量;
**Usage** :

```sas
GROUPBY = ARMN
```

[**Example**](#一般用法)
用法同 [GROUPBY](../qualify_multi/readme.md#groupby)

---

Expand Down
37 changes: 3 additions & 34 deletions docs/quantify_multi_test/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
- [INDATA](#indata)
- [VAR](#var)
- [GROUP](#group)
- [GROUPBY](#groupby)

### 可选参数

- [GROUPBY](#groupby)
- [PATTERN](#pattern)
- [OUTDATA](#outdata)
- [STAT_FORMAT](#stat_format)
Expand Down Expand Up @@ -41,44 +41,13 @@

### GROUP

**Syntax** : _variable_

指定分组变量。

> [!WARNING]
>
> - 参数 `GROUP` 不允许指定不存在于参数 `INDATA` 指定的数据集中的变量;
> - 参数 `GROUP` 不允许指定数值型变量;
**Usage** :

```sas
GROUP = ARM
```

[**Example**](#一般用法)
用法同 [GROUP](../quantify_multi/readme.md#group)

---

### GROUPBY

**Syntax** : _variable_<(ASC\<ENDING\> | DESC\<ENDING\>)>

指定分组变量的排序。

本参数同时决定了检验统计量的正负性,若参数 `GROUP` 包含 `试验组``对照组` 两个分类,对应 `GROUPBY` 的值分别为 1、2,则进行差异性检验时,统计量的正负性与 `试验组-对照组` 的正负性一致。

> [!WARNING]
>
> - 参数 `GROUPBY` 不允许指定不存在于参数 `INDATA` 指定的数据集中的变量;
**Usage** :

```sas
GROUPBY = ARMN
```

[**Example**](#一般用法)
用法同 [GROUPBY](../quantify_multi/readme.md#groupby)

---

Expand Down
9 changes: 9 additions & 0 deletions gbk/qualify.sas
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Version Date: 2023-03-08 1.0.1
2024-07-19 1.0.23
2024-09-18 1.0.24
2024-11-13 1.0.25
2024-11-14 1.0.26
===================================
*/

Expand Down Expand Up @@ -128,6 +129,14 @@ Version Date: 2023-03-08 1.0.1
%put ERROR: 在 &libname_in 逻辑库中没有找到 &memname_in 数据集!;
%goto exit_with_error;
%end;

proc sql noprint;
select count(*) into : nobs from &indata;
quit;
%if &nobs = 0 %then %do;
%put ERROR: 分析数据集 &indata 为空!;
%goto exit_with_error;
%end;
%end;
%end;
%put NOTE: 分析数据集被指定为 &libname_in..&memname_in;
Expand Down
12 changes: 12 additions & 0 deletions gbk/qualify_multi.sas
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Version Date: 2023-12-26 0.1
2024-06-04 0.8
2024-06-13 0.9
2024-07-15 0.10
2024-11-14 0.11
===================================
*/

Expand Down Expand Up @@ -166,8 +167,19 @@ Version Date: 2023-12-26 0.1
%else %do;
%let IS_GROUP_LEVEL_SPECIFIED = TRUE;
%let group_level_n = %sysfunc(countw(%bquote(&group_level), %bquote(,), %bquote(sq)));

%do i = 1 %to &group_level_n;
%let group_level_&i = %sysfunc(scan(%bquote(&group_level), &i, %bquote(,), %bquote(sq)));
%let group_level_unquote_&i = %sysfunc(compress(&&group_level_&i, %nrstr(%")));
%let group_level_freq_&i = "&&group_level_unquote_&i(频数)";
%let group_level_freq_fmt_&i = "&&group_level_unquote_&i(频数格式化)";
%let group_level_n_&i = "&&group_level_unquote_&i(频数)(兼容)";
%let group_level_n_fmt_&i = "&&group_level_unquote_&i(频数格式化)(兼容)";
%let group_level_times_&i = "&&group_level_unquote_&i(频次)";
%let group_level_times_fmt_&i = "&&group_level_unquote_&i(频次格式化)";
%let group_level_rate_&i = "&&group_level_unquote_&i(频率)";
%let group_level_rate_fmt_&i = "&&group_level_unquote_&i(频率格式化)";
%end;
%end;
%end;
Expand Down
5 changes: 2 additions & 3 deletions gbk/qualify_multi_test.sas
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ Version Date: 2024-01-08 0.1
2024-06-13 0.9
2024-07-15 0.10
2024-11-13 0.11
2024-11-14 0.12
===================================
*/

%macro qualify_multi_test(INDATA,
VAR,
GROUP,
GROUPBY,
GROUPBY = #AUTO,
BY = #AUTO,
UID = #NULL,
PATTERN = %nrstr(#FREQ(#RATE)),
Expand All @@ -45,8 +46,6 @@ Version Date: 2024-01-08 0.1

/*----------------------------------------------初始化----------------------------------------------*/
/*统一参数大小写*/
%let group = %sysfunc(strip(%bquote(&group)));
%let groupby = %upcase(%sysfunc(strip(%bquote(&groupby))));
%let del_temp_data = %upcase(%sysfunc(strip(%bquote(&del_temp_data))));

/*声明全局变量*/
Expand Down
12 changes: 7 additions & 5 deletions gbk/quantify_multi.sas
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Version Date: 2023-12-21 0.1
2023-12-25 0.2
2024-01-05 0.3
2024-01-19 0.4
2024-11-14 0.5
===================================
*/

Expand Down Expand Up @@ -168,6 +169,7 @@ Version Date: 2023-12-21 0.1
%if %superq(groupby) ^= %bquote() and %superq(groupby) ^= #AUTO %then %do;
%put WARNING: 已通过参数 GROUP 指定了分组的排序,参数 GROUPBY 已被忽略!;
%end;
%let groupby_criteria = &group_var;
%end;
%else %do;
%if %superq(groupby) = %bquote() %then %do;
Expand All @@ -183,15 +185,15 @@ Version Date: 2023-12-21 0.1
%else %do;
%let reg_groupby_id = %sysfunc(prxparse(%bquote(/^([A-Za-z_][A-Za-z_\d]*)(?:\(((?:ASC|DESC)(?:ENDING)?)\))?$/)));
%if %sysfunc(prxmatch(&reg_groupby_id, %superq(groupby))) %then %do;
%let groupby_var = %sysfunc(prxposn(&reg_groupby_id, 1, %superq(groupby)));
%let groupby_criteria = %sysfunc(prxposn(&reg_groupby_id, 1, %superq(groupby)));
%let groupby_direction = %sysfunc(prxposn(&reg_groupby_id, 2, %superq(groupby)));

/*检查排序变量存在性*/
proc sql noprint;
select type into :type from DICTIONARY.COLUMNS where libname = "&libname_in" and memname = "&memname_in" and upcase(name) = "&groupby_var";
select type into :type from DICTIONARY.COLUMNS where libname = "&libname_in" and memname = "&memname_in" and upcase(name) = "&groupby_criteria";
quit;
%if &SQLOBS = 0 %then %do; /*数据集中没有找到变量*/
%put ERROR: 在 &libname_in..&memname_in 中没有找到分组排序变量 &groupby_var;
%put ERROR: 在 &libname_in..&memname_in 中没有找到分组排序变量 &groupby_criteria;
%goto exit_with_error;
%end;

Expand All @@ -200,8 +202,8 @@ Version Date: 2023-12-21 0.1
select
distinct
&group_var,
&groupby_var
from %superq(indata) where not missing(&group_var) order by &groupby_var &groupby_direction, &group_var;
&groupby_criteria
from %superq(indata) where not missing(&group_var) order by &groupby_criteria &groupby_direction, &group_var;
select quote(strip(&group_var)) into : group_level_1- from tmp_quantify_m_groupby_sorted;
select count(distinct &group_var) into : group_level_n from tmp_quantify_m_groupby_sorted;
quit;
Expand Down
11 changes: 6 additions & 5 deletions gbk/quantify_multi_test.sas
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Version Date: 2024-01-05 0.1
2024-01-23 0.3
2024-05-29 0.4
2024-06-14 0.5
2024-11-14 0.6
===================================
*/

%macro quantify_multi_test(INDATA,
VAR,
GROUP,
GROUPBY,
GROUPBY = #AUTO,
OUTDATA = RES_&VAR,
PATTERN = %nrstr(#N(#NMISS)|#MEAN±#STD|#MEDIAN(#Q1, #Q3)|#MIN, #MAX),
STAT_FORMAT = #AUTO,
Expand All @@ -38,7 +39,7 @@ Version Date: 2024-01-05 0.1

/*声明全局变量*/
%global qtmt_exit_with_error
groupby_var;
groupby_criteria;
%let qtmt_exit_with_error = FALSE;

/*声明局部变量*/
Expand Down Expand Up @@ -211,7 +212,7 @@ Version Date: 2024-01-05 0.1
/*正态性检验*/
proc univariate data = tmp_qmt_indata normaltest noprint;
var %superq(VAR);
class &groupby_var;
class &groupby_criteria;
output out = tmp_qmt_nrmtest normaltest = normaltest probn = probn;
run;

Expand Down Expand Up @@ -239,7 +240,7 @@ Version Date: 2024-01-05 0.1
%put NOTE: 至少一个组别不符合正态性,使用 Wilcoxon 检验!;
proc npar1way data = tmp_qmt_indata wilcoxon noprint;
var %superq(VAR);
class &groupby_var;
class &groupby_criteria;
output out = tmp_qmt_wcxtest wilcoxon;
run;
proc sql noprint;
Expand All @@ -261,7 +262,7 @@ Version Date: 2024-01-05 0.1
ods output TTests = tmp_qmt_ttests Equality = tmp_qmt_equality;
proc ttest data = tmp_qmt_indata plots = none;
var %superq(VAR);
class &groupby_var;
class &groupby_criteria;
run;
ods html;

Expand Down
9 changes: 9 additions & 0 deletions utf8/qualify.sas
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Version Date: 2023-03-08 1.0.1
2024-07-19 1.0.23
2024-09-18 1.0.24
2024-11-13 1.0.25
2024-11-14 1.0.26
===================================
*/

Expand Down Expand Up @@ -128,6 +129,14 @@ Version Date: 2023-03-08 1.0.1
%put ERROR: 在 &libname_in 逻辑库中没有找到 &memname_in 数据集!;
%goto exit_with_error;
%end;

proc sql noprint;
select count(*) into : nobs from &indata;
quit;
%if &nobs = 0 %then %do;
%put ERROR: 分析数据集 &indata 为空!;
%goto exit_with_error;
%end;
%end;
%end;
%put NOTE: 分析数据集被指定为 &libname_in..&memname_in;
Expand Down
12 changes: 12 additions & 0 deletions utf8/qualify_multi.sas
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Version Date: 2023-12-26 0.1
2024-06-04 0.8
2024-06-13 0.9
2024-07-15 0.10
2024-11-14 0.11
===================================
*/

Expand Down Expand Up @@ -166,8 +167,19 @@ Version Date: 2023-12-26 0.1
%else %do;
%let IS_GROUP_LEVEL_SPECIFIED = TRUE;
%let group_level_n = %sysfunc(countw(%bquote(&group_level), %bquote(,), %bquote(sq)));

%do i = 1 %to &group_level_n;
%let group_level_&i = %sysfunc(scan(%bquote(&group_level), &i, %bquote(,), %bquote(sq)));
%let group_level_unquote_&i = %sysfunc(compress(&&group_level_&i, %nrstr(%")));
%let group_level_freq_&i = "&&group_level_unquote_&i(频数)";
%let group_level_freq_fmt_&i = "&&group_level_unquote_&i(频数格式化)";
%let group_level_n_&i = "&&group_level_unquote_&i(频数)(兼容)";
%let group_level_n_fmt_&i = "&&group_level_unquote_&i(频数格式化)(兼容)";
%let group_level_times_&i = "&&group_level_unquote_&i(频次)";
%let group_level_times_fmt_&i = "&&group_level_unquote_&i(频次格式化)";
%let group_level_rate_&i = "&&group_level_unquote_&i(频率)";
%let group_level_rate_fmt_&i = "&&group_level_unquote_&i(频率格式化)";
%end;
%end;
%end;
Expand Down
5 changes: 2 additions & 3 deletions utf8/qualify_multi_test.sas
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ Version Date: 2024-01-08 0.1
2024-06-13 0.9
2024-07-15 0.10
2024-11-13 0.11
2024-11-14 0.12
===================================
*/

%macro qualify_multi_test(INDATA,
VAR,
GROUP,
GROUPBY,
GROUPBY = #AUTO,
BY = #AUTO,
UID = #NULL,
PATTERN = %nrstr(#FREQ(#RATE)),
Expand All @@ -45,8 +46,6 @@ Version Date: 2024-01-08 0.1

/*----------------------------------------------初始化----------------------------------------------*/
/*统一参数大小写*/
%let group = %sysfunc(strip(%bquote(&group)));
%let groupby = %upcase(%sysfunc(strip(%bquote(&groupby))));
%let del_temp_data = %upcase(%sysfunc(strip(%bquote(&del_temp_data))));

/*声明全局变量*/
Expand Down
Loading

0 comments on commit 669f53e

Please sign in to comment.