Create a file .dat that includes the date

I want to create a file .dat with two columns, the first one with the date and the second one with my data. Any idea?

I have been trying with this code but doesn't work well...

load data[456,2]=C:---.txt;
x=data;
dataset="y";
let vnames= {"date" "y" };
DAY = datestrymd(date);
let vnames= {"DAY" "y" };
y=saved(x,dataset,vnames);

2 Answers



0



I see a few things wrong with the code snippet you supplied. I will reproduce it below with some comments, explaining what each line of code is doing and then create a simple example.

//Load a 456 by 2 matrix into 'data'
load data[456,2]=C:---.txt;

//Set 'x' equal to the recently loaded data
x=data;

//Set 'dataset' to equal the string 'y',
//which is used below to create the
//the GAUSS dataset 'y.dat'
dataset = "y";

//Create a 1x2 character vector
let vnames= { "date" "y" };

//Call the 'data' function to return
//a 4x1 vector containing today's date
//then pass that output to 'datestrymd' to
//turn the 4x1 date vector into a GAUSS 'dtscalar' date 
DAY = datestrymd(date);

//Overwrite the GAUSS variable 'vnames', created above
let vnames= { "DAY" "y" };

//Create a GAUSS dataset with 2 variables:
//The first named 'DAY' and the second named 'y',
//as the variable names are taken from 'vnames'
//The first variable, 'DAY' will contain the data
//the first column of 'x'. The second variable,
'y' will contain the data from the second column
//of 'x'
y=saved(x,dataset,vnames);

Assuming we are using a recent version of GAUSS, we can do this instead:

//Create a 4x2 example matrix, where the first
//column contains dates in dtscalar format
my_data = { 20150101 2.3,
            20150201 1.9,
            20150301 1.7,
            20150401 2.1 };

//Create a 1x2 character vector for variable names
vnames = { "DATE" "y" };

//Create a variable containing the name to give the dataset
dataset_name = "example_data";

//Create a dataset named 'example_data.dat'
//containing the data from 'my_data'. The first
//first column will be named 'DATE', the
//second column will be named 'y'
ret = saved(my_data, dataset_name, vnames);

You can load the data after running the above code, like this:

new_x = loadd("example_data");

and print out the variable names like this:

new_vnames = getname("example_data");

print $new_vnames;

aptech

1,773


0



Thank you!

Your Answer

2 Answers

0

I see a few things wrong with the code snippet you supplied. I will reproduce it below with some comments, explaining what each line of code is doing and then create a simple example.

//Load a 456 by 2 matrix into 'data'
load data[456,2]=C:---.txt;

//Set 'x' equal to the recently loaded data
x=data;

//Set 'dataset' to equal the string 'y',
//which is used below to create the
//the GAUSS dataset 'y.dat'
dataset = "y";

//Create a 1x2 character vector
let vnames= { "date" "y" };

//Call the 'data' function to return
//a 4x1 vector containing today's date
//then pass that output to 'datestrymd' to
//turn the 4x1 date vector into a GAUSS 'dtscalar' date 
DAY = datestrymd(date);

//Overwrite the GAUSS variable 'vnames', created above
let vnames= { "DAY" "y" };

//Create a GAUSS dataset with 2 variables:
//The first named 'DAY' and the second named 'y',
//as the variable names are taken from 'vnames'
//The first variable, 'DAY' will contain the data
//the first column of 'x'. The second variable,
'y' will contain the data from the second column
//of 'x'
y=saved(x,dataset,vnames);

Assuming we are using a recent version of GAUSS, we can do this instead:

//Create a 4x2 example matrix, where the first
//column contains dates in dtscalar format
my_data = { 20150101 2.3,
            20150201 1.9,
            20150301 1.7,
            20150401 2.1 };

//Create a 1x2 character vector for variable names
vnames = { "DATE" "y" };

//Create a variable containing the name to give the dataset
dataset_name = "example_data";

//Create a dataset named 'example_data.dat'
//containing the data from 'my_data'. The first
//first column will be named 'DATE', the
//second column will be named 'y'
ret = saved(my_data, dataset_name, vnames);

You can load the data after running the above code, like this:

new_x = loadd("example_data");

and print out the variable names like this:

new_vnames = getname("example_data");

print $new_vnames;
0

Thank you!


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.