<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>errors &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/tag/errors/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Tue, 23 Apr 2024 20:22:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Understanding Errors: G0058 Index out-of-Range</title>
		<link>https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/</link>
					<comments>https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 27 Aug 2021 17:16:16 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[index out-of-range]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581656</guid>

					<description><![CDATA[Today we will help you to understand and resolve <code>Error G0058 Index Out-of-Range</code> We will :
<ol>
<li> Explain the cause of the index out-of-range error in GAUSS.</li>
<li> Explain why performing index assignments past the end of your data can lead to bad outcomes.</li>
<li>Show how to use some functions and operators that can assist with diagnosing and resolving this error.</li>
<li> Work through an example to resolve an indexing problem.</li>
</ol>
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today's blog will:</p>
<ol>
<li>Explain the cause of the index out-of-range error in GAUSS.</li>
<li>Explain why performing index assignments past the end of your data can lead to bad outcomes.</li>
<li>Show how to use some functions and operators that can assist with diagnosing and resolving this error.</li>
<li>Work through an example to resolve an indexing problem.</li>
</ol>
<h2 id="what-causes-the-index-out-of-range-error">What Causes the Index-out-of-Range Error?</h2>
<p>The index out-of-range error occurs any time that you try to select an element of a <a href="https://www.aptech.com/blog/what-is-a-gauss-dataframe-and-why-should-you-care/" target="_blank" rel="noopener">dataframe</a>, matrix, or string array that does not exist. Let's look at a basic example:</p>
<h3 id="index-out-of-range-on-read">Index out-of-range on read</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create a 2x1 vector
a = { 5, 9 };

// Attempt to access the third element and assign it to 'b'
b = a[3];</code></pre>
<p>In the above example, the error is clear. Since <code>a</code> does not have a third element, trying to access it is clearly an error.</p>
<h3 id="index-out-of-range-on-write">Index out-of-range on write</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create a 2x1 vector
a = { 5, 9 };

// Attempt to assign to the third element of 'a'
a[3] = 12;</code></pre>
<p>Since this code is attempting to write past the end of the vector <code>a</code>, it will also cause an index out-of-range error. This behavior is standard among most programming environments. However, it can sometimes confuse new GAUSS users who are coming from statistical software that has historically been designed more for prototyping.</p>
<p>At first, it might seem convenient for the extra elements to be automatically added past the end of your data. However, there are two reasons why it is not such a good idea:</p>
<ol>
<li><strong>It allows errors to go undetected</strong>. Writing past the end of data is very easy to do by accident and one of the most common errors to make when programming--even for trained professional programmers. Letting the error go undetected at the source can cause a much harder-to-detect error to happen later on in the program. In other cases, <em>it can even lead to wrong answers</em>.</li>
<li><strong>It will slow down your code</strong>. Starting out with a vector, matrix, or dataframe of the correct size and filling it in can be 10 or more times faster than adding new elements an observation at a time.</li>
</ol>
<h2 id="functions-and-operators-to-investigate-and-resolve-an-index-out-of-range-error">Functions and Operators to Investigate and Resolve an Index out-of-range Error</h2>
<p>Here are a few functions and operators that should be helpful when diagnosing and resolving an index out-of-range error.</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://docs.aptech.com/gauss/cols.html" target="_blank" rel="noopener">cols</a></td>
<td>Returns the number of columns in a dataframe, matrix, or string array.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/rows.html" target="_blank" rel="noopener">rows</a></td>
<td>Returns the number of rows in a dataframe, matrix, or string array.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/getorders.html" target="_blank" rel="noopener">getorders</a></td>
<td>Returns the size of each dimension in a dataframe, matrix, multi-dimensional array, or string array.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/getorders.html" target="_blank" rel="noopener">zeros</a></td>
<td>Returns a matrix of a specified size filled with zeros. It is often used to pre-allocate a matrix that will be filled in later.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Symbol</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>~</td>
<td>Adds columns to a matrix, dataframe, or string array.</td>
</tr>
<tr>
<td>|</td>
<td>Adds rows to a matrix, dataframe, or string array.</td>
</tr>
</tbody>
</table>
<h3 id="basic-usage-examples">Basic Usage Examples</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a = { 7 2,
      4 1 };

b = { 5 8,
      3 9 };

c = { 6 6 };

print "rows(a) = " rows(a);
print "cols(a) = " cols(a);
print "----";
print "getorders(a) = " getorders(a);</code></pre>
<p>will return:</p>
<pre>rows(a) =        2.0000000
cols(a) =        2.0000000
----
getorders(a) =
       2.0000000
       2.0000000 </pre>
<p>Continuing with the previous code:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Use horizontal concatenation to add columns
d = a ~ b;

// User vertical concatenation to add rows
e = c | b;</code></pre>
<p>After the above code:</p>
<pre>d = 7 2 5 8
    4 1 3 9

e = 6 6
    5 8
    3 9</pre>
<h2 id="solve-an-example-index-error">Solve an Example Index Error</h2>
<p>Let's work through a simplified real-world example of an out-of-range error. Our code takes some <a href="https://www.aptech.com/blog/basic-bootstrapping-in-gauss/" target="_blank" rel="noopener">bootstrap</a> samples from a dataset and then computes and stores the means and standard deviations of these samples. Here is the initial code:</p>
<pre class="hljs-container hljs-container-solo"><code>burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws, 1);

for i(1, ndraws + burn_in, 1);
    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>After running the above code, GAUSS reports the index out-of-range error from the line <code>stats[i,2] = stdsc(s);</code>.</p>
<p>Let's start diagnosing this problem by printing out the size of <code>stats</code> before the loop and the value of <code>i</code> on each iteration, like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws, 1);

print "rows(stats) = " rows(stats);
print "cols(stats) = " cols(stats);

for i(1, ndraws + burn_in, 1);

    print "i = " i;

    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>After running this version, we see the following printed output:</p>
<pre>rows(stats) =        10.000000
cols(stats) =        1.0000000
i =        1.0000000 </pre>
<p>This tells us that the error happened on the first iteration of the loop, since <code>i</code> is never greater than one. We also see that <code>stats</code> only has one column. The line causing our error is trying to write to the second column of <code>stats</code>. So we need to add a second column to <code>stats</code> when we pre-initialize it.</p>
<p>After we fix that problem, our code looks like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws, 2);

print "rows(stats) = " rows(stats);
print "cols(stats) = " cols(stats);

for i(1, ndraws + burn_in, 1);

    print "i = " i;

    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>Unfortunately, GAUSS is still reporting an index out-of-range error. This time it is on an earlier line, <code>stats[i,1] = meanc(s);</code>. However, when we look at our printed output:</p>
<pre>rows(stats) =        10.000000
cols(stats) =        2.0000000
i =        1.0000000
i =        2.0000000
i =        3.0000000
i =        4.0000000
i =        5.0000000
i =        6.0000000
i =        7.0000000
i =        8.0000000
i =        9.0000000
i =        10.000000
i =        11.000000 </pre>
<p>we see that the code has gotten through several iterations. We can also see that the error occurs when the code tries to write to the 11th row of <code>stats</code>, but <code>stats</code> only has 10 rows. We need to find out why the number of iterations in the loop and the number of rows in <code>stats</code> don't agree.</p>
<p>Looking back over the code, we can see that <code>stats</code> has <code>ndraws</code> rows, but the loop has <code>ndraws</code> + <code>burn_in</code> iterations. There are many ways we could resolve this, but since our main focus is on identifying the cause of the problem, we will just change the size of <code>stats</code> to have enough rows to hold all iterations.</p>
<p>Below is our final code:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws + burn_in, 2);

print "rows(stats) = " rows(stats);
print "cols(stats) = " cols(stats);

for i(1, ndraws + burn_in, 1);

    print "i = " i;

    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>Fortunately, this time the code runs without error and the printout shows us that all iterations have been performed--problem solved! We can now remove the print statements and keep going.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Congratulations! You have learned:</p>
<ol>
<li>The cause of the index out-of-range error in GAUSS.</li>
<li>Why performing index assignments past the end of your data can lead to bad outcomes.</li>
<li>How to use some functions and operators that can assist with finding the size of your data and adding rows and columns.</li>
</ol>
<p>and worked through a simple, but realistic example.</p>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/" target="_blank" rel="noopener">Understanding Errors | G0025 : Undefined symbol</a></li>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/" target="_blank" rel="noopener">Understanding Errors: G0064 Operand Missing</a></li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Errors: G0064 Operand Missing</title>
		<link>https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/</link>
					<comments>https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Mon, 26 Jul 2021 14:26:38 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[operand]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581524</guid>

					<description><![CDATA[Today we will help you to understand and resolve Error G0064: Operand Missing. We will answer the questions:

<ol>
<li>What is an operand?</li>
<li> How do common mathematical and non-mathematical operators interact with operands?</li>
<li>What are common causes of operand missing errors?</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today we will help you to understand and resolve <code>Error G0064: Operand Missing</code>. We will answer the questions:</p>
<ul>
<li>What is an operand?</li>
<li>How do common mathematical and non-mathematical operators interact with operands?</li>
<li>What are common causes of operand missing errors?</li>
</ul>
<h2 id="what-is-an-operand">What is an operand?</h2>
<p>An operand is a symbol that an operator operates on. For example, in the line below:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">X = 4 + 5;</code></pre>
<p>The plus sign is the operator and both <code>4</code> and <code>5</code> are operands.</p>
<h2 id="mathematical-and-logical-operators">Mathematical and Logical Operators</h2>
<p>When you think of operators, the mathematical and logical operators tend to come to mind first. For example, operators like those shown in the table below.</p>
<table>
 <thead>
 <tr>
      <th style="background-color: #36434C" colspan="3"><span style="color:#FFFFFF">Mathematical and Logical Operators</span>
      </th>
   </tr>
<tr><th>Operator</th><th>Purpose</th>
</tr></thead>
<tbody>
<tr><td><code>+</code></td><td>Addition.</td></tr>
<tr><td><code>*</code>, <code>.*</code></td><td>Multiplication and element-by-element multiplication.</td></tr>
<tr><td><code>^</code></td><td>Exponentiation.</td></tr>
<tr><td><code>==</code>, <code>.==</code></td><td>Logical equality and element-by-element logical equality.</td></tr>
<tr><td><code>!==</code>, <code>.!==</code></td><td>Logical not equal and element-by-element logical not equal
</td></tr><tr><td><code>&gt;</code>, <code>.&gt;</code></td><td>Greater than and element-by-element greater.</td></tr>
</tbody>
</table>
<h3 id="operand-missing-errors-with-mathematical-and-logical-operators">Operand Missing Errors with Mathematical and Logical Operators</h3>
<p>Missing operand errors that occur with mathematical operators tend to be simple to understand and fix, so we will only show one example.</p>
<p><strong>Example 1</strong></p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Multiply 6 by 5 
// and print  
// the result
6.*5;</code></pre></td><td><pre><code>// The left-hand 
// operand is 
// missing
.*5;</code></pre></td></tr>
<tr><td>The element-by-element multiplication operator requires two operands, one on the right-hand side and one on the left.</td><td>The code snippet is missing the left side operand and will return the operand missing error.</td></tr>
</tbody>
</table>
<h2 id="non-mathematical-operators">Non-mathematical Operators</h2>
<p>Unlike the logical and mathematical operators, many of the “other” operators are not commonly noticed or considered.</p>
<table>
 <thead>
 <tr>
      <th style="background-color: #36434C" colspan="3"><span style="color:#FFFFFF">Non-mathematical Operators</span>
      </th>
   </tr>
<tr><th>Operator</th><th>Description</th><th>Purpose</th>
</tr></thead>
<tbody>
<tr><td><code>,</code></td><td>Commma</td><td>Separates items in lists.</td></tr>
<tr><td><code> </code></td><td>Space</td><td>Separates items in print statements and indices inside index brackets.</td></tr>
<tr><td><code>.</code></td><td>Period</td><td>Signifies all rows or all columns inside of index brackets.</td></tr>
<tr><td><code>:</code></td><td>Colon</td><td>Creates a continuous series of indices inside of index brackets.</td></tr></tbody>
</table>
<h3 id="comma-operator-examples">Comma Operator Examples</h3>
<p><strong>Comma Operator Example One</strong></p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Create a 4x2 matrix with 
// random normally 
// distributed numbers
X = rndn(4,2);</code></pre></td><td><pre><code>// No operands on either 
// side of the comma 
// operator
X = rndn(,);</code></pre></td></tr>
<tr><td>The comma operator is used to separate the operands 4 and 2.</td><td>The comma operator is used, but there are no operands for the comma operator to separate. </td></tr>
</tbody>
</table>
<p><strong>Comma Operator Example Two</strong></p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Assign the element from  
// the 6th row and first 
// column to Z
Z = X[6,1];</code></pre></td><td><pre><code>// The operand to the right 
// of the comma operator 
// is missing
Z = X[6, ];</code></pre></td></tr>
<tr><td>The comma operator separates the index operands 6 and 1.</td><td>The comma operator is used, but there is not a column index on the right side of the comma.</td></tr>
</tbody>
</table>
<h3 id="colon-operator-example">Colon Operator Example</h3>
<p>Operand missing statements with the colon operator will look like the previous comma operator errors. </p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Assign the 3rd to 5th 
// elements from the vector
// y to u
u = y[3:5];</code></pre></td><td><pre><code>// The operand to the
// right of the colon 
// operator is missing
u = y[3: ];</code></pre></td></tr>
<tr><td>The colon operator separates the index operands 3 and 5.</td><td>The colon operator is used, but there is not a column index on the right side of the colon.</td></tr>
</tbody>
</table>
<h2 id="print-statements-and-the-space-operator">Print Statements and the Space Operator</h2>
<p>The usage of space operator is probably the most likely “operand missing” error to trip up new GAUSS users.</p>
<p>The <a href="https://docs.aptech.com/gauss/print.html" target="_blank" rel="noopener"><code>print</code></a> statement takes a space-separated list of items to print. For example:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">print 4 5 6;</code></pre>
<p>will return:</p>
<pre>4.0000    5.0000    6.0000</pre>
<p>Similarly, we can print the same data with variables like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">A = 4;
B = 5;

print A B 6;</code></pre>
<p>And GAUSS will again return:</p>
<pre>4.0000    5.0000    6.0000</pre>
<p>So far this is quite simple and something you may have done without a thought. However, adding an operator can cause a problem. For example, because the <code>print</code> statement uses the space operator to separate the items to print, the statement:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">print A + B;</code></pre>
<p>is interpreted by GAUSS as the following instructions:</p>
<p>Print the value of A.<br />
Print the value of +.<br />
Print the value of B.    </p>
<p>Therefore, when GAUSS gets to the <code>+</code> sign, it does not see enough operands, because it has already been told to print A.</p>
<p>You can resolve this by removing the space operator between <code>A</code>, <code>+</code> and <code>B</code>, or by adding parentheses around the statement.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">A = 4;
B = 5;

// Option 1: Add parentheses 
// around the sum of A and B
print (A + B);

// Option 2: Remove space operator 
// to print the sum of A and B
print A+B;</code></pre>
<p>The parentheses (or dropped spaces) only need to be around the operator. The table below shows a few variations and the resulting printed output.</p>
<table>
 <thead>
<tr><th>Statement</th><th>Output</th></tr>
</thead>
<tbody>
<tr><td><pre><code>print (4 + 5) 6;</code></pre></td><td><code>9.0000    6.0000</code></td></tr>
<tr><td><pre><code>print (4 + 5)*6;</code></pre></td><td><code>54.0000</code></td></tr>
<tr><td><pre><code>print  ((4 + 5) / 6);</code></pre></td><td><code>1.5000</code></td></tr>
<tr><td><pre><code>print 4 5*6;</code></pre></td><td><code>4.0000 30.0000</code></td></tr>
</tbody></table>
<h3 id="conclusion">Conclusion</h3>
<p>Congratulations! In today's blog, you have learned:</p>
<ul>
<li>What mathematical, logical, and non-mathematical operands are in GAUSS. </li>
<li>Common causes of the <code>G0064: Operand Missing</code> error.</li>
</ul>
<h3 id="further-reading">Further reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/" target="_blank" rel="noopener">Understanding Errors | G0025 : Undefined symbol</a></li>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/" target="_blank" rel="noopener">Understanding Errors: G0058 Index out-of-Range</a></li>
<li><a href="https://www.aptech.com/blog/gauss-basics-6-logical-and-relational-operators/" target="_blank" rel="noopener">GAUSS Basics 6: Logical and relational operators</a></li>
</ol>
<p>    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script></p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Errors &#124; G0025 : Undefined symbol</title>
		<link>https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/</link>
					<comments>https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 23 Apr 2021 18:21:41 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[undefined symbol]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581214</guid>

					<description><![CDATA[Today we will help you to understand and resolve <code>Error G0025: Undefined symbol</code> We will answer the questions:
<ol>
<li> What is a GAUSS symbol</li>
<li> What are the most common types of GAUSS symbols?</li>
<li>How do I define a GAUSS symbol?</li>
<li> How do I resolve the error `G0025: Undefined symbol`?</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today we will help you to understand and resolve <code>Error G0025: Undefined symbol</code>. We will answer the questions:</p>
<ul>
<li>What is a GAUSS symbol?</li>
<li>What are the most common types of GAUSS symbols?</li>
<li>How do I define a GAUSS symbol?</li>
<li>How do I resolve the error <code>G0025: Undefined symbol</code>?</li>
</ul>
<h2 id="what-is-a-symbol">What is a symbol?</h2>
<p>In GAUSS a symbol is a label used to represent some data, a procedure or function. For example, in the code below:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a = 3;
b = 4;</code></pre>
<p><code>a</code> and <code>b</code> are symbols representing the scalar values 3 and 4 respectively.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">c = a + b;

d = 3 + 4;</code></pre>
<p>The above code creates two new symbols, <code>c</code> and <code>d</code>.</p>
<ul>
<li><code>c</code> is created by applying the addition operator to the previously created symbols, <code>a</code> and <code>b</code>. </li>
<li><code>d</code> is created by adding two literal values. </li>
</ul>
<p>Numbers, such as the integers <code>3</code> and <code>4</code> are called <em>literals</em>, rather than <em>symbols</em>.</p>
<h2 id="how-to-define-a-symbol">How to define a symbol</h2>
<p><strong>Numeric and string symbols</strong> are defined in GAUSS using the equals sign as we saw previously. Here are some more examples:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Define the symbol 'e' to be a 3x1 vector
e = { 2.1, 0.9, 3.8 };

// Define the symbol 'f' to be the
// largest element of the vector 'e'
f = maxc(e);

// Define the symbol 'g' to be a 10x2 random normal matrix
g = rndn(10,2);

// Define the symbol 'h' to be a string
h = "String symbols contain text";</code></pre>
<p><strong>Procedure (<code>proc</code>) and function (<code>fn</code>) names</strong> are also symbols. Below are some simple examples of procedure definitions:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** The procedure and function definitions below define the symbols
** 'doubleIt' and 'squareIt'.
*/

proc (1) = doubleIt(X);
    retp(X .* 2);
endp;

fn squareIt(X) = X .^ 2;</code></pre>
<div class="alert alert-info" role="alert">Read more about <a href="https://www.aptech.com/blog/basics-of-gauss-procedures/" target="_blank" rel="noopener">creating GAUSS procedures</a> in this blog post.</div>
<h2 id="basic-undefined-symbol-examples">Basic undefined symbol examples</h2>
<p>Any time a symbol is referenced on the right side of an equation before it has been defined can cause <code>Error G00025: Undefined symbol</code>. Here are a few simple examples:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear out all symbols in the GAUSS workspace
new;

// Since 'a' has not been defined,
// this line will cause an error
b = a;</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear out all symbols in the GAUSS workspace
new;

b = 3;

// Since 'a' has not been defined,
// this line will cause an error
c = a + b;</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear out all symbols in the GAUSS workspace
new;

a = { 2, 4, 6 };

// Since the procedure 'foo' has not been defined,
// this line will cause an error
X = foo(a);</code></pre>
<h2 id="solve-a-simple-undefined-symbols-error">Solve a simple undefined symbols error</h2>
<p>If we run a file named <code>estimate.gss</code> with the following contents:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all symbols from the GAUSS workspace
new;

/*
** Simulate random normal variables
*/
X = rndn(nobs, nvars);

/*
** Simulate a random normal response variable
*/
y = rndn(nobs, 1);

/*
** Estimate a linear model
*/
call glm(y, X, "normal");</code></pre>
<p>we will get the following error messages:</p>
<pre>G0025 : Undefined symbol: 'nobs'  [estimate.gss, line 6]
G0025 : Undefined symbol: 'nvars' [estimate.gss, line 6]</pre>
<p>These error messages tell us that line 6 of our code is using two symbols that have not yet been defined, <code>nobs</code> and <code>nvars</code>. To resolve these errors, we need to set those symbols to appropriate values.</p>
<p>The inputs to the <a href="https://docs.aptech.com/gauss/rndn.html" target="_blank" rel="noopener"><code>rndn</code></a> function need to be scalar values that represent the number of rows and columns of the output matrix. We set them to 100 and 4 respectively in the code below to resolve the errors.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all symbols from the GAUSS workspace
new;

// Specify the number of observations to simulate
nobs = 100;

// Specify the number of columns to simulate
nvars = 4;

/*
** Simulate random normal variables
*/
X = rndn(nobs, nvars);

/*
** Simulate a random normal response variable
*/
y = rndn(nobs, 1);

/*
** Estimate a linear model
*/
call glm(y, X, "normal");</code></pre>
<p>After these changes the code will run successfully.</p>
<h2 id="what-causes-undefined-proc-or-function-symbols">What causes undefined proc or function symbols?</h2>
<p>Now let's move to a less obvious example. Let's suppose we have a file <code>arimafit-example.gss</code> with these contents:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all symbols from GAUSS workspace
new;

// Create file name with full path
fname = getGAUSSHome() $+ "pkgs/tsmt/examples/enders_sim2.dat";

p = 3;
d = 1;
q = 1;

// Run arima estimation
call arimaFit(fname, "ar2", p, d, q);</code></pre>
<p>When we run this file, we get the error:</p>
<pre>G0025 : Undefined symbol: 'arimaFit' [arimafit-example.gss, line 12]</pre>
<p>In this example, we can tell that <code>arimaFit</code> is a GAUSS procedure or function. There are four main reasons why a procedure or function might be undefined in your GAUSS code:</p>
<h3 id="1-it-was-added-in-a-newer-version-of-gauss-than-you-have">1. It was added in a newer version of GAUSS than you have.</h3>
<p>You can search the <a href="https://docs.aptech.com/gauss/changelog.html" target="_blank" rel="noopener">GAUSS Change Log</a> for the procedure or function to see if it has been added in a newer version.</p>
<h3 id="2-it-is-in-a-library-that-you-do-not-have-loaded">2. It is in a library that you do not have loaded.</h3>
<p><a href="https://docs.aptech.com/gauss/tsmt/arimafit.html" target="_blank" rel="noopener"><code>arimaFit</code></a> from our above code snippet is from the <a href="https://docs.aptech.com/gauss/tsmt/index.html" target="_blank" rel="noopener">GAUSS Time Series MT</a> add-on package. If this is the case, you will need to <a href="https://www.aptech.com/blog/using-gauss-packages-complete-guide/" target="_blank" rel="noopener">make sure that the package is installed and loaded</a> correctly.</p>
<p>Undefined references to the procedures <code>maxset</code>, <code>optset</code>, <code>maxlik</code> and <code>optmum</code> are sometimes found undefined in publicly available third-party code.</p>
<h3 id="3-it-is-in-a-code-file-that-gauss-has-not-been-told-about">3. It is in a code file that GAUSS has not been told about.</h3>
<p><a href="https://www.aptech.com/blog/basics-of-gauss-procedures/#define_procs" target="_blank" rel="noopener">Our Basics of GAUSS Procedures blog</a> explains the four ways to tell GAUSS about your user-defined procedure. </p>
<div class="alert alert-info" role="alert">The symbol named could also be misspelled, but the <a href="https://www.aptech.com/blog/controlling-the-gauss-autocomplete-behavior/" target="_blank" rel="noopener">GAUSS autocomplete</a> should help prevent that.</div>
<h3 id="4-running-the-code-line-by-line">4. Running the code line-by-line</h3>
<p>When you run a file all at once, GAUSS allows you to place procedures wherever you like, such as the end of the file.</p>
<pre class="hljs-container hljs-container-solo"><code>new;

a = 3;

b = doubleIt(a);

proc (1) = doubleIt(x);
    retp(2 * x);
endp;</code></pre>
<p>However, if you run a program file like the one above, line-by-line, you will get an undefined symbol error. If you run the entire file at once, GAUSS will search the file for any procedures that it does not know about. However, when you run the code line-by-line, GAUSS only runs the code you tell it to run.</p>
<p>You can resolve this problem, by either:</p>
<ol>
<li>Running the code under the debugger.</li>
<li>Adding the procedures to a GAUSS library or <a href="https://www.aptech.com/blog/basics-of-gauss-procedures/#dot_g_proc_file" target="_blank" rel="noopener">a <code>.g</code> file</a>.</li>
<li>Highlighting all lines of the needed procedures and running them first.</li>
</ol>
<h2 id="conclusion">Conclusion</h2>
<p>Congratulations! In today's blog, you have learned that:</p>
<ul>
<li>GAUSS symbols are labels, or names, that represent data, procedures and functions.</li>
<li>Use of a symbol on the right side of an equation before it is defined, or assigned a value, can cause an undefined symbol error.</li>
<li>Symbols are commonly defined by using the equals operator as well as loading libraries.</li>
</ul>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/" target="_blank" rel="noopener">Understanding Errors: G0064 Operand Missing</a></li>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/" target="_blank" rel="noopener">Understanding Errors: G0058 Index out-of-Range</a></li>
<li><a href="https://www.aptech.com/blog/make-your-code-portable-data-paths/" target="_blank" rel="noopener">Make your code portable: Data paths</a></li>
<li><a href="https://www.aptech.com/blog/the-current-working-directory-what-you-need-to-know/" target="_blank" rel="noopener">The Current Working Directory: What you need to know</a></li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What you need to know about #include</title>
		<link>https://www.aptech.com/blog/what-you-need-to-know-about-include/</link>
					<comments>https://www.aptech.com/blog/what-you-need-to-know-about-include/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 02 Nov 2018 19:22:29 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=17829</guid>

					<description><![CDATA[If you have run much publicly available GAUSS code, you have probably come across the `#include` command. In this blog, we answer some important questions about #include:
<ol>
<li> What does `#include` do?</li>
<li> What is the most common error when using `#include`?</li>
<li>How can I resolve the most common error?</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>If you have run much publicly available GAUSS code, you have probably come across the <code>#include</code> command. Since it is used so much, it will be helpful to answer these questions:</p>
<ol>
<li>What does <code>#include</code> do?</li>
<li>What is the most common error when using <code>#include</code>?</li>
<li>How can I resolve the most common error?</li>
</ol>
<h2 id="what-does-include-do">What does #include do?</h2>
<p>The <code>#include</code> command is almost exactly like an instruction telling GAUSS to copy-and-paste the contents of one file into another. It is often used so that a file containing procedures and/or control variables can be kept separate from the main code file.</p>
<h3 id="example-without-include">Example without #include</h3>
<p>For example, let's imagine we have a file named <code>hypotenuse.gss</code> with the following contents:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a = 3;
b = 4;

c = hypotenuse(a, b);

proc (1) = hypotenuse(a,b);
    retp(sqrt(a.^2 + b.^2));
endp;</code></pre>
<p>We can run this file and it will assign <code>c</code> to be equal to 5 as we expect.</p>
<h3 id="example-with-include">Example with #include</h3>
<p>If we will only ever want to use the <code>hypotenuse</code> procedure in this one file, then it is probably fine to leave it as it is. However, if this procedure will be reused a lot, it might be better to just have one copy of the procedure, instead of copy-and-pasting the procedure every time we need to use it.</p>
<p>To do this, we would break our <code>hypotenuse.gss</code> file up into two files, <code>main.gss</code> and <code>hypotenuse.src</code>. The contents of <code>main.gss</code> will be:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a = 3;
b = 4;

c = hypotenuse(a,b);

// Make hypotenuse procedure available
#include hypotenuse.src</code></pre>
<p>and the contents of <code>hypotenuse.src</code> will be:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (1) = hypotenuse(a,b);
    retp(sqrt(a.^2 + b.^2));
endp;</code></pre>
<p>As long as GAUSS can find the <code>hypotenuse.src</code> file, these versions will behave identically.</p>
<h2 id="the-most-common-include-error">The most common #include error</h2>
<p>By far the most common error occurs when GAUSS cannot find the <code>#include'd</code> file. If GAUSS could not find our <code>hypotenuse.src</code> file, we would get an error like this:</p>
<pre>G0014 : File not found 'C:\gauss\examples\hypotenuse.src'</pre>
<h3 id="where-does-gauss-look-for-the-include-file">Where does GAUSS look for the #include file?</h3>
<p>When shown an error message stating that the file cannot be found in a directory such as <code>C:\gauss\examples\</code>, people often wonder why GAUSS looked for the file in their GAUSS examples directory. GAUSS did search in the directory found in the error message. However, that is the last place that GAUSS looked. </p>
<p>The GAUSS <code>#include</code> command will search the following locations, in this order:</p>
<ol>
<li>Your current working directory.</li>
<li>The files in your <a href="https://www.aptech.com/resources/tutorials/src_path/">SRC_PATH</a>.</li>
</ol>
<h3 id="how-can-i-resolve-the-problem">How can I resolve the problem?</h3>
<p>If GAUSS cannot find a <code>#include'd</code> file you can fix the problem by either:</p>
<ol>
<li>Changing your GAUSS working directory to the folder in which the file is located.</li>
<li>Moving the file to one of the GAUSS <a href="https://www.aptech.com/resources/tutorials/src_path/">SRC_PATH</a> locations.</li>
<li>Adding a full path to the <code>#include</code> statement.</li>
</ol>
<h2 id="the-second-most-common-include-error">The second most common #include error</h2>
<div class="alert alert-info" role="alert"><strong>Update</strong>: This issue has been resolved in GAUSS version 22 and newer.</div>
<p><a href="https://www.aptech.com/wp-content/uploads/2018/11/gblog-include-pgm.png"><img src="https://www.aptech.com/wp-content/uploads/2018/11/gblog-include-pgm.png" alt="#include from the GAUSS command line." width="684" height="268" class="aligncenter size-full wp-image-18545" /></a>
The second most common error with <code>#include</code> occurs when either:</p>
<ol>
<li>Entering the <code>#include</code> command in the <strong>Program Input/Output</strong> window.</li>
<li>Running a <code>#include</code> statement by right-clicking and selecting <strong>Run Selected Text</strong>, or <strong>Run Current Line</strong>.</li>
</ol>
<p>Either of these will return an error like this:</p>
<pre>G0008: Syntax error '#include hypotenuse.src'</pre>
<p>This is because <code>#include</code> statements must be run as part of a program file.</p>
<h3 id="how-can-i-resolve-the-problem-1">How can I resolve the problem?</h3>
<p>If you would like to execute the command <code>#include &lt;filename&gt;</code> in the GAUSS <strong>Program Input/Output</strong> window, simply replace <code>#include</code> with <code>run</code>. </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Use the 'run' statement at the GAUSS command line
run hypotenuse.src</code></pre>
<p>The <code>run</code> command will execute the code in the file exactly as if the <code>#include</code> statement was run as part of a program file.</p>
<h3 id="conclusions">Conclusions</h3>
<p>Today we have learned:</p>
<ol>
<li>What the <code>#include</code> command does in GAUSS.</li>
<li>Why it is used.</li>
<li>The two most common errors associated with its usage.</li>
<li>Methods to resolve common errors.</li>
</ol>
<p>Code and data from this blog can be found <a href="https://github.com/aptech/gauss_blog/tree/master/programming/include-statements-11.02.18">here</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/what-you-need-to-know-about-include/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
