Dealing with multiple CSV file imports for parameters, how?

I am defining several dozens of parameters in GAMS Studio up to four dimensions. Let’s use three of them as examples.
abcst(abx,ghg) description1
ablim(ghg,abx,tp,rg) description2
abmlt(tp) description3

For each parameter, I have an Excel table (named the same as the parameters) with the following headings: Dim1, Dim2, Dim3, Dim4, Value
So there would be a table called abcst with the first rows:
|Dim1|Dim2|Dim3|Dim4|Value|
|ab1|co2|||10|
|ab1|ch4|||0.07|
|ab1|n2o|||0.81|

Then I created a macro to export each of the tables to CSV into a folder: /data/csvfolder
The macro also creates a file with the names of the tables/parameters called parameterlist.txt saved under /data/parameterlist.txt

I want to create a code in GAMS that reads each of the CSV files in the folder, extracts the info and stores it in a GDX file. The code I have now is this, but it is not working.


* Set up paths to load parameters
$set csvDirectory "Data\Parameters"
$set paramListPath "Data\parameterlist.txt"

* Check if the parameterlist.txt file exists
$if not exist %paramListPath% $abort "parameterlist.txt not found!"

* Define a set to hold the parameter names from parameterlist.txt
SET paramList /read %paramListPath%/;

* Loop over each parameter in the list and load its data
$onEcho > load_parameters.gms
loop(paramList(param),
    $setLocal paramName param.tl
    $setLocal csvFile "%csvDirectory%\%paramName%.csv"
    $if not exist %csvFile% $abort "%paramName%.csv not found!"

* Use ondelim to import CSV data into a table
    table tempData(*,*,*,*)  Temporary table to hold CSV data
    $ondelim
    $include %csvFile%
    $offdelim

* Transfer data from table to parameter based on the correct dimensionality
    if (card(tempData) > 0,
        if (card(Dim4) > 0,
            %paramName%(Dim1, Dim2, Dim3, Dim4) = tempData(Dim1, Dim2, Dim3, Dim4);
        else if (card(Dim3) > 0,
            %paramName%(Dim1, Dim2, Dim3) = tempData(Dim1, Dim2, Dim3);
        else if (card(Dim2) > 0,
            %paramName%(Dim1, Dim2) = tempData(Dim1, Dim2);
        else if (card(Dim1) > 0,
            %paramName%(Dim1) = tempData(Dim1);
        );
    );
);
$offEcho

* Include the generated GAMS script to load parameters
$include load_parameters.gms

* Save all parameters into a GDX file
execute_unload "referenceParamComplete_test.gdx";