loading multiple files at once

Hello,

Is there a way in gauss to load multiple excel files using do while loop?

for example,

I have many excel file called file(1), file(2), ...file(n)

I wrote the following code:

i=1;

y=zeros(bigt,n);

do while i<=n;

    data=xlsreadm(file(i), "A1:A100",1);

    y[.,i]=data;

    i=i+1;

endo;

The error message I get is that file(i) is not found. My code may be incorrect. Any help, suggestion or alternative way to compile and merge data from multiple files is appreciated.

Thanks in advance

2 Answers



0



If you are getting the file not found error, it could be that:

  • Your working directory is different than the directory of your files and you did not add a path to the file names.
  • The path was incorrect.

Here is an example using GAUSS example files that works.

new;

fnames = "xle_daily.xlsx" $| "tbill_3mo.xlsx";

// Add full path
path = getGAUSSHome() $+ "examples/";
fnames = path $+ fnames;

// Print names for verification
print fnames;

y = zeros(rows(fnames), 10);

for i(1, rows(fnames), 1);
    // Read a 10 element column vector.
    // Transpose and write to 'y'
    y[i,.] = xlsReadM(fnames[i], "B2:B11")';
endfor;

print y;

aptech

1,773


0



Thanks for your help.

Your Answer

2 Answers

0

If you are getting the file not found error, it could be that:

  • Your working directory is different than the directory of your files and you did not add a path to the file names.
  • The path was incorrect.

Here is an example using GAUSS example files that works.

new;

fnames = "xle_daily.xlsx" $| "tbill_3mo.xlsx";

// Add full path
path = getGAUSSHome() $+ "examples/";
fnames = path $+ fnames;

// Print names for verification
print fnames;

y = zeros(rows(fnames), 10);

for i(1, rows(fnames), 1);
    // Read a 10 element column vector.
    // Transpose and write to 'y'
    y[i,.] = xlsReadM(fnames[i], "B2:B11")';
endfor;

print y;

0

Thanks for your help.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.