我对 SAS 很陌生。我已从两个 Excel 电子表格导入数据。从一开始,我计算了新变量名称吸着率和 Kfs。这一步效果很好。然后,我将新创建的变量(其中有 24 个)与第二个表(有 237 个观察值)合并。第一个表中的 21 个观察值对应于第二个表中的 21 个独特的处理 x 块组合,因此实际上每个处理 x 块的吸着率和 Kfs 值被添加多次,对应于时间和 CI 条目(有 7 到 12 个时间)和每个治疗 x 块的 CI 条目)。这 3 个“缺失条目”是已从第二个表中删除的异常值。
我想运行一个非线性模型(CI = 吸着率 * sqrt(Time) + Kfs)。它必须为我提供每个治疗 x 块组合的输出。我希望看到时间、CI、吸着率和 Kfs 的原始值作为输出,以及与每次测量相对应的预测 CI 值。
在 ChatGPT 的帮助下,我设置了以下代码,但遇到了错误,并且因为错误位于宏内,所以我收到了额外的假脱机错误,这意味着我无法确定错误是。我希望有人能帮助我找出问题所在以及如何纠正。
%macro run_model(treatment, block, time, ci, s, k);
data temp;/* Create local macro variables */
merge infiltration (where=(Treatment = "&treatment" and Block = "&block"))
InfilNewData (where=(Treatment = "&treatment" and Block = "&block"));
by Treatment Block;
Time = &time;
CI = &ci;
Sorptivity = &s;
Kfs = &k;
run;
proc nlin data=temp;
parms Sorptivity = &s Kfs = &k;
model CI = Sorptivity * sqrt(Time) + Kfs;
output out=PredictedCI_&treatment Block=Block Time=Time CI=CI Sorptivity=Sorptivity Kfs=Kfs predicted=PredictedCI;
run;
data PredictedCI_&treatment;/* Add a Treatment group identifier to the output */
set PredictedCI_&treatment;
Treatment = "&treatment";
Block = "&block";
run;
%mend;
%macro run_all_models;
%local treatment_list block_list s_list k_list time_list ci_list;
/* Create macro variable lists within the macro */
proc sql noprint;
select distinct Treatment into :treatment_list separated by ' ' from InfilDF;
select distinct Block into :block_list separated by ' ' from InfilDF;
select distinct Sorptivity into :s_list separated by ' ' from InfilNewData;
select distinct Kfs into :k_list separated by ' ' from InfilNewData;
select distinct Time into :time_list separated by ' ' from InfilDF;
select distinct CI into :ci_list separated by ' ' from InfilDF;
quit;
/* Loop over the macro variables and run the models */
%do i = 1 %to %sysfunc(countw(&treatment_list));
%let current_treatment = %scan(&treatment_list, &i);
%let current_block = %scan(&block_list, &i);
%let current_s = %scan(&s_list, &i);
%let current_k = %scan(&k_list, &i);
%let current_time = %scan(&time_list, &i);
%let current_ci = %scan(&ci_list, &i);
%run_model(¤t_treatment, ¤t_block, ¤t_time, ¤t_ci, ¤t_s, ¤t_k);
proc print data=PredictedCI_¤t_treatment;
run;
%end;
%mend;
%run_all_models;
在 run_model 宏中,我最初设置
data temp
以获取仅源自名为 InfilDF 的组合 DF 的局部变量,该组合 DF 具有如上所述的所有 4 个数值变量。然后,我尝试将其更改为您在此处看到的代码,该代码从两个原始表中提取变量。结果/错误是相同的:
WHERE (Treatment='Biochar10tha') and (Block='Block1');
22: LINE and COLUMN cannot be determined.
ERROR 22-322: Syntax error, expecting one of the following: ;, (, /, ESS, H, J, L95,
L95M, LCL, LCLM, LMAX, OUT, P, PARMS, PRED, PREDICTED, PRES, PROJRES,
PROJSTUDENT, PRSTUD, R, RESEXPEC, RESIDUAL, REXPEC, SSE, STDI, STDP, STDR,
STUDENT, U95, U95M, UCL, UCLM, WEIGHT.
76: LINE and COLUMN cannot be determined.
ERROR 76-322: Syntax error, statement will be ignored.
数据和代码可在以下位置获取:https://github.com/AnelD13/SAS_infiltration。我发现错误的两个主要位置都在设置临时 DF 的第一个宏中以及模型代码本身中。吸附率和 Kfs 宏变量的设置方式可能存在问题,因为之前的错误都指出了这一点。
对于任何寻找类似答案的人,我最终将其简化为以下内容:
proc nlin data=InfilDF;
parms Sorptivity=0.01 Kfs=0.01;
model CI = Sorptivity * sqrt(Time) + Kfs;
by Treatment Block;
output out=PredictedResults predicted=PredictedCI;
run;
data InfilPredicted;
retain Block Treatment Time CI Infiltration Sorptivity Kfs; /* I had to do this as my Time
variable showed up empty*/
merge InfilDF PredictedResults;
by Treatment Block;
run;
proc sort data=InfilPredicted;
by Treatment Block Time;
run;
proc print data=InfilPredicted;
run;