Here is one approach that may help. Consider the following three functions. The first function, tname
, returns a table name as a string. For example, "table0053". The second function, fname
returns a file name. For example, "table0053.csv". The third fundtion, vname
, returns a variable name. For example, table0053
.
ClearAll[tname, fname, vname, "table*"]
tname[n_] := "table" <> StringJoin[ToString /@ IntegerDigits[n, 10, 4]]
fname[n_] := tname[n] <> ".csv"
vname[n_] := ToExpression[tname[n]]
We can use these functions to generate the tables. Importantly, in order to use vname
on the left of the = (Set
command), we must Clear
the variable name and use Evaluate
. The following code creates three variables, table0053
, table0192
and table2301
.
Evaluate[vname[53]] = Table[{i, i + 1}, {i, 1, 8}];
Evaluate[vname[192]] = Table[{j, 2*j}, {j, 1, 12}];
Evaluate[vname[2301]] = Table[{k, 5 + k}, {k, 1, 4}];
table2301
(* {{1, 6}, {2, 7}, {3, 8}, {4, 9}} *)
To list the names of all of the table variables, use Names["table*"]
. Now we can export a single table like this
Export[fname[2301], vname[2301], "CSV"];
Import[%, "Text"]
(* "1,6
2,7
3,8
4,9" *)
A sequence of tables can be exported like this
Do[Export[fname[k], vname[k], "CSV"],
{k, {53, 192, 2301}}]