<?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>Statskom</title>
	<atom:link href="http://statskom.com/tag/sas-naotes/feed/" rel="self" type="application/rss+xml" />
	<link>http://statskom.com</link>
	<description>Clinical programming</description>
	<lastBuildDate>Thu, 05 Oct 2017 09:04:02 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.8.41</generator>
	<item>
		<title>SAS tips &amp; tricks #9 &#8211; NOTE: Variable X is uninitialized.</title>
		<link>http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/</link>
		<comments>http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/#comments</comments>
		<pubDate>Thu, 09 Oct 2014 18:07:22 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[NOTE: Variable X is uninitialized.]]></category>
		<category><![CDATA[SAS errors]]></category>
		<category><![CDATA[sas naotes]]></category>
		<category><![CDATA[sas tips and tricks]]></category>
		<category><![CDATA[SAS warnings]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=440</guid>
		<description><![CDATA[<p>The &#8220;NOTE: Variable X is uninitialized&#8221; message is a result of trying to run a DATA Step which utilizes a variable that is not present in the input dataset or has not been created at the point within the DATA&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/">SAS tips &#038; tricks #9 &#8211; NOTE: Variable X is uninitialized.</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>The &#8220;NOTE: Variable X is uninitialized&#8221; message is a result of trying to run a DATA Step which utilizes a variable that is not present in the input dataset or has not been created at the point within the DATA Step where SAS tries to utilize the variable.</p>
<h2>What causes the message?</h2>
<p>This message occurs when a DATA Step  attempts to use a variable which is either not present in the input dataset or has not been created in a preceding step. For example, if the variable was drop or not kept in in the input dataset, or if the code to create it has been accidentally omitted.</p>
<h2>What happens when this occurs?</h2>
<p>When SAS encounters an uninitialized variable within a DATA Step, SAS will:</p>
<ul>
<li>outputs a message to a log stating the name of the uninitialized variable.</li>
<li>set the uninitialized variable to missing, i.e. create a null numeric variable.</li>
<li>continue to create the output dataset.</li>
</ul>
<h2>How to resolve it?</h2>
<p>To resolve this issue, ensure that the uninitialized variable is available in your dataset at the point at which it is first required.</p>
<h3><span style="font-size: 1.5em; line-height: 1.5em;">Example</span></h3>
<p>The following code reads the SASHELP.CLASS dataset and attempts to create a new variable BSA_GRP, based on the value of a variable BSA:</p>
<pre>DATA class;
  SET sashelp.class;
  IF bsa &gt; 1 THEN bsa_grp = 1;
  ELSE IF bsa&gt; 1 THEN bsa_grp = 2;
RUN;</pre>
<p>This code results in the following messages being printed to the log.:</p>
<pre> NOTE: Variable bsa is uninitialized.
 NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 NOTE: The data set WORK.CLASS has 19 observations and 7 variables.</pre>
<p>The first line tells us that the variable BSA was uninitialized (not available) at the point in the DATA Step where it was first required. The remaining lines tell us that despite the uninitialized variable, the dataset WORK.CLASS is still created.</p>
<p>We confirm this by opening the output dataset, which will be as follows:<br />
<a href="http://statskom.com/wp-content/uploads/2014/10/class.png"><img class="alignnone size-full wp-image-441" alt="class" src="http://statskom.com/wp-content/uploads/2014/10/class.png" width="1564" height="340" /></a></p>
<p>We see that SAS has created the output dataset, we also notice that it contains an empty numeric variable BSA.</p>
<p>To resolve this issue, either the BSA variable should be present in the input dataset or else it should be created in the current DATA Step prior to the statement in which the BSA variable is first used, for example:</p>
<pre>DATA class;
  SET sashelp.class;
  bsa = ((height *weight )/ 3131 )**1/2
  IF bsa &gt; 1 THEN bsa_grp = 1;
  ELSE IF bsa&gt; 1 THEN bsa_grp = 2;
RUN;</pre>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/">SAS tips &#038; tricks #9 &#8211; NOTE: Variable X is uninitialized.</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #8 &#8211; NOTE: Numeric values have been converted to charater values</title>
		<link>http://statskom.com/sas-tips-tricks-8-note-numeric-values-have-been-converted-to-character-values/</link>
		<comments>http://statskom.com/sas-tips-tricks-8-note-numeric-values-have-been-converted-to-character-values/#comments</comments>
		<pubDate>Tue, 16 Sep 2014 19:41:39 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[dirty data]]></category>
		<category><![CDATA[implicit data type conversion]]></category>
		<category><![CDATA[SAS errors]]></category>
		<category><![CDATA[sas naotes]]></category>
		<category><![CDATA[sas tips and tricks]]></category>
		<category><![CDATA[SAS warnings]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=348</guid>
		<description><![CDATA[<p>In the last post SAS tips &#38; tricks #7 we looked at how to avoid implicit character to numeric conversion.  Here we look at what causes numeric to character implicit conversions and how to avoid them In a similar way&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-8-note-numeric-values-have-been-converted-to-character-values/">SAS tips &#038; tricks #8 &#8211; NOTE: Numeric values have been converted to charater values</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In the last post<a href="http://statskom.com/sas-tips-tricks-7-note-character-values-converted-numeric-values-places-given/"> SAS tips &amp; tricks #7 </a>we looked at how to avoid implicit character to numeric conversion.  Here we look at what causes numeric to character implicit conversions and how to avoid them</p>
<p><span style="font-size: 14px; line-height: 1.5em;">In a similar way to character to numeric implicit conversions, this  message occurs when you try to use a numeric variable in a function that requires a character argument, or to assign a numeric value to a variable which has already been defined as numeric.</span></p>
<p>It is possible to rely on SAS to perform these conversions imlpicitly, however, in general this is not considered good programming practice and it is usually preferable to perform these conversions explicitly. Implicit conversions also take more CPU time than explicit conversions and so may cause your program to execute more slowly.</p>
<p>Consider the following example, where we try to concatenate the character variable type with the numeric variable horsepower.</p>
<pre>DATA cars;
  SET sashelp.cars;
  type_horse = STRIP(type)!!"-"!!horsepower;
RUN;</pre>
<p>The output is created however the log displays the following message.</p>
<pre> 43         DATA cars;
 44           SET sashelp.cars;
 45           type_horse = STRIP(type)!!"-"!!horsepower;
 46         RUN;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       45:34</pre>
<p>This tells us that the code in line 45 of the log, at column 34 numeric variable has been used where a character variable was expected. In our case, the concatenation function (!!) expects a character variable, however horespower is numeric.</p>
<p>As the output dataset has been created, it may be tempting to leave the code as is, and have SAS perform the conversion for you. However, printing the dataset shows why this approach can be dangerous, as shown below.</p>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td valign="bottom" width="52">
<p align="right"><b>Obs</b></p>
</td>
<td valign="bottom" width="159"><b> type_horse</b></td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top" width="52">
<p align="right"><b>1</b></p>
</td>
<td valign="top" width="159">SUV-         265</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>2</b></p>
</td>
<td valign="top" width="159">Sedan-         200</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>3</b></p>
</td>
<td valign="top" width="159">Sedan-         200</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>4</b></p>
</td>
<td valign="top" width="159">Sedan-         270</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>5</b></p>
</td>
<td valign="top" width="159">Sedan-         225</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>6</b></p>
</td>
<td valign="top" width="159">Sedan-         225</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>7</b></p>
</td>
<td valign="top" width="159">Sports-         290</td>
</tr>
</tbody>
</table>
</div>
<p>Note how instead of being concatenated directly onto the hyphen, the horsepower, there are many leading spaces prior to the digits. These leading spaces are created by the implicit data conversion. When SAS performs this implicit numeric to character conversion it must select the format to use when performing the conversion and the width of the converted string. By default, SAS uses a format of BEST12, since our horsepower values each contains three digits, it means that SAS pads the values with nine leading spaces when performing the concatenation.</p>
<p>This issue can be avoided by first using the PUT function to convert the values from numeric to character. As shown in the example below.</p>
<pre>DATA cars;
  SET sashelp.cars;
  type_horse = STRIP(type)!!"-"!!PUT(horsepower,3.);
RUN;</pre>
<p>The second argument of the PUT functions allows you to specify the format that should be used during the conversion. As the horsepower values all have three digits, we specify a format of 3., which means that the value of horsepower is written as a character string of three digits in the concatenation. This also removes the converted to warning message from the log.</p>
<p>Finally a prinnt of the dataset confirms that the leading spaces have indeed been removed.</p>
<div align="center">
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td valign="bottom" width="52">
<p align="right"><b>Obs</b></p>
</td>
<td valign="bottom" width="117"><b>type_horse</b></td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top" width="52">
<p align="right"><b>1</b></p>
</td>
<td valign="top" width="117">SUV-265</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>2</b></p>
</td>
<td valign="top" width="117">Sedan-200</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>3</b></p>
</td>
<td valign="top" width="117">Sedan-200</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>4</b></p>
</td>
<td valign="top" width="117">Sedan-270</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>5</b></p>
</td>
<td valign="top" width="117">Sedan-225</td>
</tr>
<tr>
<td valign="top" width="52">
<p align="right"><b>6</b></p>
</td>
<td valign="top" width="117">Sedan-225</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-8-note-numeric-values-have-been-converted-to-character-values/">SAS tips &#038; tricks #8 &#8211; NOTE: Numeric values have been converted to charater values</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-8-note-numeric-values-have-been-converted-to-character-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #7 &#8211; NOTE: Character values have been converted to numeric values</title>
		<link>http://statskom.com/sas-tips-tricks-7-note-character-values-converted-numeric-values-places-given/</link>
		<comments>http://statskom.com/sas-tips-tricks-7-note-character-values-converted-numeric-values-places-given/#comments</comments>
		<pubDate>Thu, 04 Sep 2014 16:21:52 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[dirty data]]></category>
		<category><![CDATA[implicit data type conversion]]></category>
		<category><![CDATA[SAS errors]]></category>
		<category><![CDATA[sas naotes]]></category>
		<category><![CDATA[sas tips and tricks]]></category>
		<category><![CDATA[SAS warnings]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=336</guid>
		<description><![CDATA[<p>In the last two posts we looked at how to clean the log by removing SAS NOTEs, here we look again at what to do when your log contains the following message: NOTE: Character values have been converted to numeric&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-7-note-character-values-converted-numeric-values-places-given/">SAS tips &#038; tricks #7 &#8211; NOTE: Character values have been converted to numeric values</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In the last two posts we looked at how to clean the log by removing SAS NOTEs, here we look again at what to do when your log contains the following message:</p>
<h3>NOTE: Character values have been converted to numeric values.</h3>
<p>This  message occurs when you try to perform a numeric calculation using a character variable, or to assign a character value to a variable which has already been defined as numeric.</p>
<p>It is possible to rely on SAS to perform these conversions imlpicitly, however, in general this is not considered good programming practice and it is usually preferable to perform these conversions explicitly. Implicit conversions also take more CPU time than explicit conversions and so may cause your program to execute more slowly.</p>
<p>Here we look at a few example where this implicit conversion is performed and look at ways in which the programs can be updated to avoid the NOTE.</p>
<p>Consider for example the following DATA step. A character variable WEIGHT_KG is created and assigned the value &#8220;75&#8243;, the subsequent statement attempts to use this character variable in a numeric calculation. In this instance SAS will perform an implicit conversion (i.e. SAS automatically converts the variable from character to numeric so that the calculation can take place). Here the character variable &#8220;75&#8243; is converted to a numeric variable and the statement executes giving the expected result, but writing a NOTE to the log explaining that SAS has had to perform an implicit conversion in order for the calculation to take place.</p>
<pre>DATA weight;
  weight_kg = "75";
  weigth_st = 0.157473 * weight_kg;
RUN;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      35:26</pre>
<p>To avoid the note being written to the log, you can explicitly perform the character to numeric conversion.</p>
<p>Going back to our example, this would involve using an INPUT function to convert the variable WEIGHT_KG to a numeric before the calculation takes place as follows:</p>
<pre>DATA weight;
  weight_kg = "75";
  weigth_st = 0.157473 * INPUT(weight_kg,BEST.);
RUN;</pre>
<p>Care should be taken with this approach however, in case the character variable contains values unsuitable for a numeric conversion. Consider the following example:</p>
<pre>DATA vitals;
  weight = "70.5";
  OUTPUT;
  weight = "U";
  OUTPUT;
RUN;

DATA vitals2;
  SET vitals;
  weight_rnd = ROUND(INPUT(weight,BEST.));
RUN;</pre>
<p>The second observation of this dataset would cause _ERROR_ variable to be set to 1 as the INPUT function tries to convert the character value &#8220;U&#8221; to a number. In this instance the log will show something similar to the following:</p>
<p>NOTE: Invalid argument to function INPUT at line 36 column 22. weight=U weight_rnd=. _ERROR_=1 _N_=2</p>
<p>Indicating that at observation 2 the variable WEIGHT contained a value &#8220;U&#8221; which was unsiotable for the INPUT function.</p>
<p>If the value of &#8220;U&#8221; is unexpected and perhaps indicates dirty data, then the best approach is usually to request that the input dataset is queried. If however the value is feasible, perhaps indicating that the test was not perofmed in this instance, then conditional programming can be used to indicate that the character to numeric conversion should only be performed on suitable input values, for example:</p>
<p>In the below example we use the ?? format modifier to first test to see whether the character variable contains a value which is suitable for conversion to a numeric, and then only perform the conversion if this is the case, otherwise a custom warning is written to the log indicating that the input data is not clean and that this should be investigated.</p>
<pre>DATA vitals2;
  SET vitals;
  IF  INPUT(weight,??BEST.) NE . THEN weight_rnd = ROUND(INPUT(weight,BEST.));
  ELSE IF weight NE "U" THEN PUT "WARN" "ING: the following non numeric values were found in the WEIGHT variable: " weight "at observation:" _n_;
RUN;</pre>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-7-note-character-values-converted-numeric-values-places-given/">SAS tips &#038; tricks #7 &#8211; NOTE: Character values have been converted to numeric values</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-7-note-character-values-converted-numeric-values-places-given/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
