arrays - 问题:引用数组值,但返回零
问题描述
我一直在研究随机选择数组中的项目。下面,我概述了我的过程。我已成功完成第 6 步(进行了许多数据检查),但由于某种原因,当我引用数组时,我收到一个零值。这一直令人困惑,因为即使我检查原始排序数据并注意某个值,检索到的值也是零。此外,我运行了一个 VNAME 来查看它正在提取哪个变量,并且它对应于数组中的正确位置。有谁知道为什么我从数组中返回一个零值?
*STEP 1: Set all non-codes to zero;
ARRAY CEREAL [337] ha_DTQ02_1-ha_DTQ02_337;
DO i=1 to 337;
if CEREAL[i]=88888.00 THEN CEREAL[i]=0;
END;
*STEP 2: Sort so that all zero values come first and food codes come last;
call SORTN(ha_DTQ02_1-ha_DTQ02_337);
*STEP 3: Rename array in reverse order so that zeros come last and codes are first. Sort function above only works in ascending order;
RENAME ha_DTQ02_1- ha_DTQ02_337=ha_DTQ02_337-ha_DTQ02_1;
*STEP 4: Count number of cereals selected;
ARRAY CEREALS[337]ha_DTQ02_1-ha_DTQ02_337;
NUMCEREALS=0;
DO i=1 to 337;
IF CEREALS[i] NOT IN (.,0) THEN NUMCEREALS+1;
END;
*STEP 5: get a random number between those two numbers- this works just fine;
IF NUMCEREALS NE 0 THEN rand1 = rand('integer', 1, numCereals);
*ensure that your second random number isn't the same as the first random number;
if NUMCEREALS ge 2 then do until(rand2 ne rand1);
rand2 = rand('integer', 1, numCereals);
end;
*STEP 6: Pull value from array using random number.;
Note: This is where I am stuck. I have tried alternative code where I recreated a new array and tried to pull the values from that new array. I have also tried placing the code directly below before closing the do loop. When the code does run, the value for these variables is zero. After many data checks, steps 1-5 work well and achieve their goals.
dtd020Af = CEREALS (rand1);
dtd020Bf = CEREALS (rand2);
OPTIONS NOFMTERR;
run;
解决方案
SORTN
呼叫例程需要操作员才能使用OF
名单。
call SORTN(of ha_DTQ02_1-ha_DTQ02_337);
对LOG
窗户的敏锐眼睛应该向您显示警告
3214 call SORTN(ha_DTQ02_1-ha_DTQ02_337);
-----
134
WARNING 134-185: Argument #1 is an expression, which cannot be updated by the SORTN subroutine
call.
推荐阅读
- c++ - 解决方案:SPOJ:DSUBSEQ
- php - 如何通过 ID 订购不随机化 Woocommerce 的相关产品
- sql - 在 postgres 数据库中显示不存在的行数据的空值
- gradle - 使用 Gradle 4.0.2 复制到项目目录之外的目录
- ios - 在 iOS 中无法获得 PDF 页面的正确分辨率
- python - 如何删除 tkinter Frame 中的内容
- php - 标头不重定向 Unset 不取消设置
- django - 如何优化以下代码
- python - 为 Tkinter.Label 导入 gif 时出现“找不到文件”
- github - 如何防止 SonarQube 的拉取请求集成将问题报告为 Githuib 上的内联评论?