GAUSS dataset with long variable name

How can I create a GAUSS dataset with a long variable name?

vnames = "GDP_ORIGINAL"|"GDP_ADJUSTED";
create fp = sampledata with ^vnames,rows(vnames),8;
rows_written = writer(fp, rndn(10, rows(vnames)));
closeall fp;

open fp = sampledata for read;
print "dataset variable names are:";
print getnamef(fp);

dataset variable names are:

GDP_ORIG
GDP_ADJU

1 Answer



0



accepted

In the example you provided, the vnames; variable is created as a character matrix. A character matrix is a format that allows you to store character data inside of standard numeric elements. It has some efficiency advantages, but limits the name length to 8 characters. If you create your variable names as a string array, you can make variable names as long as you like. You can create a string array by either using the string concatenation operator $| instead of the numeric concatenation operator | like this:

vnames = "GDP_ORIGINAL"$|"GDP_ADJUSTED";

or by directly declaring and assigning a string array like this:

string vnames = { "GDP_ORIGINAL", "GDP_ADJUSTED" };

So your entire code might look like this:

vnames = "GDP_ORIGINAL"$|"GDP_ADJUSTED";
create fp = sampledata with ^vnames,rows(vnames),8;
rows_written = writer(fp, rndn(10, rows(vnames)));
closeall fp;

open fp = sampledata for read;
print "dataset variable names are:";
print getnamef(fp);

Which should return:

dataset variable names are:

    GDP_ORIGINAL 
    GDP_ADJUSTED 

Your Answer

1 Answer

0
accepted

In the example you provided, the vnames; variable is created as a character matrix. A character matrix is a format that allows you to store character data inside of standard numeric elements. It has some efficiency advantages, but limits the name length to 8 characters. If you create your variable names as a string array, you can make variable names as long as you like. You can create a string array by either using the string concatenation operator $| instead of the numeric concatenation operator | like this:

vnames = "GDP_ORIGINAL"$|"GDP_ADJUSTED";

or by directly declaring and assigning a string array like this:

string vnames = { "GDP_ORIGINAL", "GDP_ADJUSTED" };

So your entire code might look like this:

vnames = "GDP_ORIGINAL"$|"GDP_ADJUSTED";
create fp = sampledata with ^vnames,rows(vnames),8;
rows_written = writer(fp, rndn(10, rows(vnames)));
closeall fp;

open fp = sampledata for read;
print "dataset variable names are:";
print getnamef(fp);

Which should return:

dataset variable names are:

    GDP_ORIGINAL 
    GDP_ADJUSTED 

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.