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
);
);
);