假設我們有一個包含 3 列的表格(範例如下)。 我透過「城市代碼」列建立表格的子集,其中將包含所有 3 列。
| 城市代碼 | 註冊號碼 | 註冊日期 |
| 032 | 0320537648 | 20201026 |
| 160 | 1600084082 | 20201020 |
| 第281章 | 2821162566 | 20201020 |
| 325 | 3250488500 | 20201024 |
| 第420章 | 4200618843 | 20201101 |
| 511 | 5110680174 | 20201027 |
| 720 | 7200054737 | 20200825 |
我只想將子集文件儲存為文字文件,如下所示:城市代碼 value.txt
我在論壇上找到了以下 jsl 腳本,該腳本對於將檔案儲存為文字檔案非常有幫助。 問題是檔案儲存為城市代碼 = value.txt
主資料表還保存了一個文字文件,這是我不想要的。
//Save as txt file
openDTs = {};
For( i = 1, i <= N Table(), i++,
Insert Into( openDTs, Data Table( i ) )
);
For( i = 1, i <= N Items( openDTs ), i++,
one_name = openDTS[i] << get name;
file_path = one_name || ".txt";
openDTS[i] << Save(file_path);
);
我對 JMP 和腳本編寫都很陌生,因此非常感謝任何想法。
下面是一個腳本,它將建立您提供的範例資料表。然後,它將建立子集,並將每個子集儲存為 .txt 檔案。
運行此範例所需要做的就是更改程式碼行
saveFolder = "C:\xxxxxxxxxxxxx\";
到保存檔案的資料夾的實際路徑,然後執行程式碼
Names Default To Here( 1 );
// Create the example data table
New Table( "Example",
Add Rows( 7 ),
New Column( "City code", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [32, 160, 281, 325, 420, 511, 720] ) ),
New Column( "Registration Number",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [320537648, 1600084082, 2821162566, 3250488500, 4200618843, 5110680174, 7200054737] )
),
New Column( "Registration Date",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [20201026, 20201020, 20201020, 20201024, 20201101, 20201027, 20200825] )
)
);
// Here is the real code.....just change the saveFolder = to the actual folder you want to
// save the files to
dt = Current Data Table();
// Create the subsets
dtSub = dt << Subset( By( :City code ),
All rows, Selected columns only( 0 ),
columns( :Registration Number, :Registration Date ) );
saveFolder = "C:\xxxxxxxxxxxxx\";
For( i = 1, i <= N Items( dtSub ), i++,
// Given the structure of the data tables created with a Subset using a By() clause
// City Code = 32
// the Word() function retuns the "32" and it is added as the name of the file to save
dtSub[i] << Save( saveFolder || Word( -1, dtSub[i] << get name, "=" ) || ".txt" )
);