SAS 到 JSL - 执行循环...我是 SAS 的长期用户,被迫学习 JSL ...
我发现在 SAS 中很容易的事情在 JSL 中似乎很难......
有人可以通过与我分享使用 JSL 生成以下嵌套 do 循环表的 JSL 代码来向我展示 Do Loops 如何在 JSL 中工作吗?
data frustration;
do temp = 1 to 10 by 1;
do press = 5 to 20 by 5;
do time = 1 to 1000 by 20;
output;
end;
end;
end;
run;
创建这些类型的模拟应该相当简单,但我似乎无法弄清楚。
脚本回复:SAS 到 JSL - 做循环......杰夫 - 很抱歉来晚了。 你超越了这个回复,我感谢你。 我没有回来检查的原因是因为我能够让它按我想要的方式工作。 非常感谢 JSL 和 SAS 差异的解释。 这真的很有帮助
回复:SAS 到 JSL - 做循环......你好@fat_angus ,欢迎成为 JMP 用户和 JMP 用户社区。
作为一名长期的 SAS 程序员(我自己也是),您需要以与考虑 SAS 的方式截然不同的方式来考虑 JMP 和 JSL。
例如,您发布了有关 SAS DATA 步骤的问题。 如您所知,DATA 步骤就是创建 SAS 数据集。 JSL 中没有直接等效的 DATA 步骤,因为 JSL 主要是关于自动化您将在 JMP 中以交互方式执行的操作。
出于这个原因,我总是鼓励人们在开始考虑他们想要自动化哪些任务之前,确保他们在交互式地使用 JMP 方面有良好的基础。
例如,要创建您在 DATA 步骤中创建的数据表,我会创建一个 File->New Table...
然后列->新列...添加一个新列并给它一个公式使用顺序()功能。

Temp columnTemp column临时列
我会对其他列做同样的事情。
press columnpress column新闻专栏
time columntime column时间栏
将行添加到数据表后,您将得到以下结果:

准备就绪后,您可以转到数据表名称旁边的红色小三角并复制表脚本。

这将为您提供以下脚本来创建一个新表:
New Table( "untitled",
Add Rows( 2000 ),
New Column( "temp",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Sequence( 1, 10, 1, 200 ) )
),
New Column( "press",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Sequence( 5, 20, 5, 50 ) )
),
New Column( "time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Sequence( 1, 1000, 20 ) ),
)
)
当然,还有其他交互式方法可以获取您在 DATA 步骤中描述的表格。 您可以使用序列创建三个表,然后使用表->加入和几个笛卡尔连接得到同一张桌子。 当您准备就绪时,JMP 可以为您提供这些步骤的脚本。
无论如何,这一切都始于了解如何使用 JMP,尤其是交互使用数据表,然后再考虑编写脚本。 毕竟,在了解 JMP 内置工具的功能之前,您不知道脚本的必要性。
在社区中不断学习并不断提问。 我们很乐意提供帮助!
回复:SAS 到 JSL - 做循环......这是伟大的 Craige_HALES!
非常感谢您抽出时间来解释。
回复:SAS 到 JSL - 做循环......再次感谢超级用户 PMROZ;这很有帮助。
回复:SAS 到 JSL - 做循环......一个完整的示例,了解开始使用一种新语言有多么困难。 (帮助-> 脚本索引和联机帮助是互补资源。 我主要使用 help->scripting 索引,提醒我它是如何工作的。 在线帮助可能更适合入门。)我在这里添加的内容比刚需的要多一些。 我忘记了关于名称大小写的 SAS 规则......
Names Default To Here( 1 );
// what does that mean? JSL has several namespaces; the 'here' namespace is for this
// editor window and means 'press' is really 'here:press' but 'dtFrustration:press' belongs to
// the table's namespace (of column names.) You could also just use different names,
// like 'iPress' for the loop control variable. JMP's variable names are almost never
// case sensitive, the weird exception being column names, which are only sensitive <BR />// if both 'Age' and 'age' are columns...Don't do that!
// an easy way to get this table script is to make a new table with the
// JMP GUI, then use the top-left red triangle to 'Copy Table Script (No Data)'.
// By convention, JSL uses 'dt' in the variable name that holds a handle to a table.
dtFrustration = New Table( "frustration",
New Column( "temp" ), // continuous numeric by default
New Column( "press" ),
New Column( "time" )
);
// because the table might be linked to other reports, there
// is a lot of hidden messaging when the table changes. A lot.
// The messaging can be shut off and later enabled for a nice speedup.
// (to see it take longer, rerun just the loop below.)
// dtFrustration << BeginDataUpdate; // pair with EndDataUpdate, below
For( temp = 1, temp <= 10, temp++,
For( press = 5, press <= 20, press += 5,
For( time = 1, time <= 1000, time += 20,
dtFrustration << addrows( 1 );
dtFrustration:time = time;
dtFrustration:temp = temp;
dtFrustration:press = press;
)
)
);
// dtFrustration << EndDataUpdate;
回复:SAS 到 JSL - 做循环......我发现通过示例更容易学习,因此请尽可能多地查看本论坛中的代码。一旦开始使用,脚本索引将真正成为您的朋友。
JSL为了循环和如果陈述,虽然在概念上很简单,但最初对我来说有点莫名其妙。缩短你的学习曲线如果,记住是函数,逗号代表然后,否则如果和别的.打开一个脚本窗口( Ctrl-T ), 在窗口中右击并选择显示嵌入式日志.粘贴以下代码并点击Ctrl-R运行它。试一试 a、b 和 c 的不同值,看看会发生什么。
a = 1;
b = 2;
c = 1;
if (a == b,
// then
print("a is equal to b");
,
// else if
a == c,
// then
print("a is equal to c");
,
// else
print("No match found for a");
);
回复:SAS 到 JSL - 做循环......谢谢...这很有帮助。
回复:SAS 到 JSL - 做循环......我听到你在说什么......谢谢......但是,这有点像有人告诉你阅读圣经以了解基督教......我花了大约 2 个小时在脚本指南中寻找如何做到这一点看似简单的概念...此外,我在编写其他脚本方面取得了很多成功...但老实说,脚本指南让我渴望在 SAS 许可证的预算中增加 20k。
我不是铁杆程序员... 我是一名工程师,只是想快速完成工作。
回复:SAS 到 JSL - 做循环......感谢 pmroz 的帮助
回复:SAS 到 JSL - 做循环......C++ 程序员 JSL 指南也可能有一些帮助。 它试图展示 JSL for 语句如何真正成为一个函数,并且知道这一点将使获得正确的语法变得容易得多。
回复:SAS 到 JSL - 做循环......所有这些都包含在脚本指南中,我非常非常强烈地建议您阅读该指南。它位于 JMP 文档库中,位于 JMP 的“帮助”下拉菜单下。
回复:SAS 到 JSL - 做循环......您来对地方了,需要帮助学习 JSL。脚本索引是您的朋友,在线文档也是如此。
这是一个代码片段,可以执行您想要的操作:
dt = data table("frustration");
for (temp = 1, temp <= 10, temp++,
for (press = 5, press <= 20, press+=5,
for (time = 1, time <= 1000, time+=20,
show(temp, press, time); // output
);
);
);