From 7ba57b9e6881a5f4e1005d3f53ae75741f969716 Mon Sep 17 00:00:00 2001 From: Firefly <45487685+Snoopy1866@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:18:37 +0800 Subject: [PATCH] =?UTF-8?q?perf(qualify=5Fmulti=5Ftest):=20=E8=A1=8C?= =?UTF-8?q?=E6=88=96=E5=88=97=E9=9D=9E=E7=BC=BA=E5=A4=B1=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=B0=91=E4=BA=8E=202=20=E6=97=B6=EF=BC=8C=E4=B8=8D=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=81=87=E8=AE=BE=E6=A3=80=E9=AA=8C=20(#68)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gbk/qualify_multi_test.sas | 46 ++++++++++++++++++------------------- utf8/qualify_multi_test.sas | 46 ++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/gbk/qualify_multi_test.sas b/gbk/qualify_multi_test.sas index 63f7e1b..076d117 100644 --- a/gbk/qualify_multi_test.sas +++ b/gbk/qualify_multi_test.sas @@ -17,6 +17,7 @@ Version Date: 2024-01-08 0.1 2024-11-14 0.12 2025-01-08 0.13 2025-01-14 0.14 + 2025-01-15 0.15 =================================== */ @@ -296,34 +297,31 @@ Version Date: 2024-01-08 0.1 %let p_format = qlmt_pvalue.; %end; - /*卡方和Fisher精确检验*/ - proc freq data = tmp_qmt_indata_unique_var noprint; - tables &var_name*&group_var /chisq(warn = (output nolog)) fisher; - output out = tmp_qmt_chisq chisq; - run; - /*定义宏变量,存储说明文字*/ %let note_stat = %unquote(%superq(indent_sql_expr)) || "统计量"; %let note_pvalue = %unquote(%superq(indent_sql_expr)) || "P值"; proc sql noprint; - select * from DICTIONARY.COLUMNS where libname = "WORK" and memname = "TMP_QMT_CHISQ"; - %if &SQLOBS = 0 %then %do; /*行或列的非缺失观测少于2,无法计算统计量*/ + select count(distinct &var_name) into :var_nonmissing_level_n from tmp_qmt_indata_unique_var where not missing(&var_name); + select count(distinct &group_var) into :group_nonmissing_level_n from tmp_qmt_indata_unique_var where not missing(&group_var); + quit; + + %if &var_nonmissing_level_n < 2 or &group_nonmissing_level_n < 2 %then %do; + /*行或列的非缺失观测少于2,无法计算统计量,输出空数据集*/ + %put NOTE: 行或列的非缺失观测少于2,无法计算统计量,将输出空数据集!; + proc sql noprint; create table tmp_qmt_stat - (idt num, seq num, item char(%eval(%length(%bquote(&indent_sql_expr)) + 12)), value_1 char(10), value_2 char(10)); - insert into tmp_qmt_stat - set idt = 1, - seq = &desc_seq_max + 1, - item = ¬e_stat, - value_1 = "-", - value_2 = "-"; - insert into tmp_qmt_stat - set idt = 1, - seq = &desc_seq_max + 2, - item = ¬e_pvalue, - value_1 = "-"; - %end; - %else %do; + (idt num, seq num, item char(10), value_1 char(10), value_2 char(10)); + quit; + %end; + %else %do; + /*卡方和Fisher精确检验*/ + proc freq data = tmp_qmt_indata_unique_var noprint; + tables &var_name*&group_var /chisq(warn = (output nolog)) fisher; + output out = tmp_qmt_chisq chisq; + run; + + proc sql noprint; select WARN_PCHI into : chisq_warn from tmp_qmt_chisq; %if &chisq_warn = 1 %then %do; /*卡方检验不适用*/ create table tmp_qmt_stat as @@ -363,8 +361,8 @@ Version Date: 2024-01-08 0.1 strip(put(P_PCHI, &p_format)) as value_1 from tmp_qmt_chisq; %end; - %end; - quit; + quit; + %end; /*4. 合并结果*/ proc sql noprint; diff --git a/utf8/qualify_multi_test.sas b/utf8/qualify_multi_test.sas index 78f499c..f44efce 100644 --- a/utf8/qualify_multi_test.sas +++ b/utf8/qualify_multi_test.sas @@ -17,6 +17,7 @@ Version Date: 2024-01-08 0.1 2024-11-14 0.12 2025-01-08 0.13 2025-01-14 0.14 + 2025-01-15 0.15 =================================== */ @@ -296,34 +297,31 @@ Version Date: 2024-01-08 0.1 %let p_format = qlmt_pvalue.; %end; - /*鍗℃柟鍜孎isher绮剧‘妫楠*/ - proc freq data = tmp_qmt_indata_unique_var noprint; - tables &var_name*&group_var /chisq(warn = (output nolog)) fisher; - output out = tmp_qmt_chisq chisq; - run; - /*瀹氫箟瀹忓彉閲忥紝瀛樺偍璇存槑鏂囧瓧*/ %let note_stat = %unquote(%superq(indent_sql_expr)) || "缁熻閲"; %let note_pvalue = %unquote(%superq(indent_sql_expr)) || "P鍊"; proc sql noprint; - select * from DICTIONARY.COLUMNS where libname = "WORK" and memname = "TMP_QMT_CHISQ"; - %if &SQLOBS = 0 %then %do; /*琛屾垨鍒楃殑闈炵己澶辫娴嬪皯浜2锛屾棤娉曡绠楃粺璁¢噺*/ + select count(distinct &var_name) into :var_nonmissing_level_n from tmp_qmt_indata_unique_var where not missing(&var_name); + select count(distinct &group_var) into :group_nonmissing_level_n from tmp_qmt_indata_unique_var where not missing(&group_var); + quit; + + %if &var_nonmissing_level_n < 2 or &group_nonmissing_level_n < 2 %then %do; + /*琛屾垨鍒楃殑闈炵己澶辫娴嬪皯浜2锛屾棤娉曡绠楃粺璁¢噺锛岃緭鍑虹┖鏁版嵁闆*/ + %put NOTE: 琛屾垨鍒楃殑闈炵己澶辫娴嬪皯浜2锛屾棤娉曡绠楃粺璁¢噺锛屽皢杈撳嚭绌烘暟鎹泦锛; + proc sql noprint; create table tmp_qmt_stat - (idt num, seq num, item char(%eval(%length(%bquote(&indent_sql_expr)) + 12)), value_1 char(10), value_2 char(10)); - insert into tmp_qmt_stat - set idt = 1, - seq = &desc_seq_max + 1, - item = ¬e_stat, - value_1 = "-", - value_2 = "-"; - insert into tmp_qmt_stat - set idt = 1, - seq = &desc_seq_max + 2, - item = ¬e_pvalue, - value_1 = "-"; - %end; - %else %do; + (idt num, seq num, item char(10), value_1 char(10), value_2 char(10)); + quit; + %end; + %else %do; + /*鍗℃柟鍜孎isher绮剧‘妫楠*/ + proc freq data = tmp_qmt_indata_unique_var noprint; + tables &var_name*&group_var /chisq(warn = (output nolog)) fisher; + output out = tmp_qmt_chisq chisq; + run; + + proc sql noprint; select WARN_PCHI into : chisq_warn from tmp_qmt_chisq; %if &chisq_warn = 1 %then %do; /*鍗℃柟妫楠屼笉閫傜敤*/ create table tmp_qmt_stat as @@ -363,8 +361,8 @@ Version Date: 2024-01-08 0.1 strip(put(P_PCHI, &p_format)) as value_1 from tmp_qmt_chisq; %end; - %end; - quit; + quit; + %end; /*4. 鍚堝苟缁撴灉*/ proc sql noprint;