<?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/category/sas-tips-tricks/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 #11 &#8211; PROC SQL; INSERT INTO</title>
		<link>http://statskom.com/sas-tips-tricks-11-proc-sql-insert-into/</link>
		<comments>http://statskom.com/sas-tips-tricks-11-proc-sql-insert-into/#comments</comments>
		<pubDate>Thu, 06 Nov 2014 08:19:52 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[INSERT INTO]]></category>
		<category><![CDATA[PROC SQL]]></category>
		<category><![CDATA[sas tips and tricks]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=465</guid>
		<description><![CDATA[<p>In this tips &#38; tricks post we look at how PROC SQL INSERT INTO provides a concise method for inserting additional rows into a dataset. Sometimes it is necessary to force additional observations into your datasets, inserting new observations into&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-11-proc-sql-insert-into/">SAS tips &#038; tricks #11 &#8211; PROC SQL; INSERT INTO</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In this tips &amp; tricks post we look at how PROC SQL INSERT INTO provides a concise method for inserting additional rows into a dataset.</p>
<p>Sometimes it is necessary to force additional observations into your datasets, inserting new observations into a dataset with the Data Step usually involves either creating ta new dataset containing the new observations using a  DATALINES statement and then appending this dataset with the original, or alternatively  using multiple OUTPUT statements  within a Data Step.</p>
<h3><strong> DATALINES method</strong></h3>
<pre>DATA class_in;
  ATTRIB name LENGTH = $8 sex LENGTH = $1;
  INFILE DATALINES;
  INPUT name sex age height weight;
  DATALINES;
Andy M 30 190 100
Ben M 60 180 110
Paul M 26 170 120
;
RUN;
PROC APPEND BASE = class DATA = class_in;
RUN;</pre>
<h3><strong>Multiple OUTPUT statement method</strong></h3>
<pre>DATA class;
  SET class;
  OUTPUT;
  name = "Andy";
  sex  = "M";
  age = 30;
  height = 190;
  weight = 100;
  OUTPUT; 
  name = "Ben";
  sex  = "M";
  age = 60;
  height = 180;
  weight = 110;
  OUTPUT; 
  name = "Paul";
  sex  = "M";
  age = 26 ;
  height = 170 ;
  weight = 120;
  OUTPUT; 
RUN;</pre>
<p>&nbsp;</p>
<h3><strong>PROC SQL INSERT INTO method</strong></h3>
<p>The DATALINES method is not ideal as it involves creating an additional dataset and ensuring that the variable lengths in the new dataset  are consistent with the length in the original dataset, otherwise truncation can occur. Whereas the Multiple OUTPUT statement method can be time consuming and error prone because it required one assignment statement to be manually typed out for each variable in each observation. The PROC SQL INSERT INTO approach provides a concise alternative to these methods. This approach inserts lines using the VALUES statement in combination with a comma separated list, as shown below:</p>
<pre>PROC SQL NOPRINT ; 
  INSERT INTO class
  VALUES ("Andy", "M", 30,190,100)
  VALUES ("Ben", "M", 60,180,110)
  VALUES ("PAUL", "M", 26,170,120); 
QUIT;</pre>
<p>If using this approach, care should be taken to ensure that the order of the values in the comma separated list is consistent with the order of the associated variable in the dataset. To minimise the possibility of making a mistake in the order, or if you want to populate certain columns only, the columns which you wish to update, and the order of the variables in your comma separated list can be specified in brackets after the name of the dataset, as shown below:</p>
<pre>PROC SQL; 
  INSERT INTO class (name,weight)
  VALUES ("Andy",100)
  VALUES ("Ben",110)
  VALUES ("PAUL",.); 
QUIT;</pre>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-11-proc-sql-insert-into/">SAS tips &#038; tricks #11 &#8211; PROC SQL; INSERT INTO</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-11-proc-sql-insert-into/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #10 &#8211; ERROR: Variable X not found.</title>
		<link>http://statskom.com/sas-tips-tricks-10-error-variable-x-not-found/</link>
		<comments>http://statskom.com/sas-tips-tricks-10-error-variable-x-not-found/#comments</comments>
		<pubDate>Sun, 12 Oct 2014 17:49:03 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[ERROR: Variable X not found]]></category>
		<category><![CDATA[SAS errors]]></category>
		<category><![CDATA[SAS notes]]></category>
		<category><![CDATA[sas tips and tricks]]></category>
		<category><![CDATA[SAS warnings]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=451</guid>
		<description><![CDATA[<p>In SAS tips &#38; tricks #9, we looked at what happens when SAS encounters an uninitialized variable within a DATA Step. Here we look at the possibly more serious scenario of what happens when SAS cannot find a reqruied variable&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-10-error-variable-x-not-found/">SAS tips &#038; tricks #10 &#8211; ERROR: Variable X not found.</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In <a title="SAS tips &amp; tricks #9 – NOTE: Variable X is uninitialized." href="http://statskom.com/sas-tips-tricks-9-note-variable-x-is-uninitialized/">SAS tips &amp; tricks #9</a>, we looked at what happens when SAS encounters an uninitialized variable within a DATA Step. Here we look at the possibly more serious scenario of what happens when SAS cannot find a reqruied variable within a PROC Step. You will usually notice that this has happened because the log will display the following message:</p>
<p><strong>&#8220;ERROR: Variable X not found&#8221; </strong></p>
<h2>What causes the message?</h2>
<p>This message occurs when a PROC Step  attempts to use a variable which is not present in the input dataset. This usually happens if, the variable was dropped or not kept in a preceding step, or if the code to create it has been accidentally omitted, or code has been copied from one place to another without making the necessary alterations.</p>
<h2>What happens when this occurs?</h2>
<p>When SAS cannot find a variable within a PROC Step, SAS will:</p>
<ul>
<li>outputs a message to a log stating the name of the variable(s) it cannot find, e.g. &#8220;<strong>ERROR: Variable X not found&#8221; </strong>implying that the variable X  is not present in the input dataset.</li>
<li>stop the execution of the current PROC Step and not produce any output.</li>
</ul>
<p>You will notice that SAS&#8217; behavior here is different to uninitialized variables in DATA Steps as in that instance it continues to create the output dataset.</p>
<h2>How to resolve it?</h2>
<p>To resolve this issue, ensure that the <em>not found</em> variable is available in the input dataset to the PROC Step, or udpate the PROC Step so that it does not require the <em>not found </em>variable in order to execute.</p>
<h3><span style="font-size: 1.5em; line-height: 1.5em;">Example</span></h3>
<p>The following code attempts to sort the SASHELP.CLASS dataset by the variables AGE, BSA and BMI variables.</p>
<pre>PROC SORT DATA = sashelp.class OUT=class;
  BY age bsa bmi;
RUN;</pre>
<p>This code results in the following messages being printed to the log.:</p>
<pre> 
 43         PROC SORT DATA = sashelp.class OUT=class;
 44           BY age bsa bmi;
 ERROR: Variable BSA not found.
 ERROR: Variable BMI not found.
 45         RUN;

 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.CLASS may be incomplete.  When this step was stopped there were 0 observations and 0 variables.</pre>
<p>The lines:</p>
<pre>ERROR: Variable BSA not found.
ERROR: Variable BMI not found.</pre>
<p>Tell us that the BSA and BMI variables respectively were not present in the dataset SASHELP.CLASS.</p>
<p>While the line:</p>
<pre> 
WARNING: The data set WORK.CLASS may be incomplete.  When this step was stopped there were 0 observations and 0 variables.</pre>
<p>Tells us that as a result of the error, the output dataset was not created.<br />
To resolve this issue, either the BSA and BMI  variables should be present in the input dataset or else they should be removed from the PROC Step.</p>
<p>For example, here we use a DATA Step to first derive the BSA variable and then remove the BMI variable from the PROC SORT:</p>
<pre>DATA class;
  SET sashelp.class;
  bsa = ((height *weight )/ 3131 )**1/2;
RUN;

PROC SORT DATA = class OUT=class2;
  BY age bsa ;
RUN;</pre>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-10-error-variable-x-not-found/">SAS tips &#038; tricks #10 &#8211; ERROR: Variable X not found.</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-10-error-variable-x-not-found/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>
		<item>
		<title>SAS tips &amp; tricks #6 – NOTE: Missing values were generated as a result of performing an operation on missing values.</title>
		<link>http://statskom.com/sas-tips-tricks-6-note-missing-values-generated-result-performing-operation-missing-values/</link>
		<comments>http://statskom.com/sas-tips-tricks-6-note-missing-values-generated-result-performing-operation-missing-values/#comments</comments>
		<pubDate>Mon, 01 Sep 2014 18:06:33 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[MEAN]]></category>
		<category><![CDATA[NOTE: Missing values were generated as a result of performing an operation on missing values.]]></category>
		<category><![CDATA[SAS errors]]></category>
		<category><![CDATA[SAS notes]]></category>
		<category><![CDATA[SAS warnings]]></category>
		<category><![CDATA[SUM]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=301</guid>
		<description><![CDATA[<p>In our last SAS tips &#38; tricks blog post (statskom.com/sas-tips-tricks-5-/) we looked at how to clean up the log by removing the &#8220;NOTE: Missing values were generated..&#8221; message. In this post we continue the theme by looking at another commonly&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-6-note-missing-values-generated-result-performing-operation-missing-values/">SAS tips &#038; tricks #6 – NOTE: Missing values were generated as a result of performing an operation on missing values.</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In our last SAS tips &amp; tricks blog post (<a title="statskom.com/sas-tips-tricks-4" href="http://statskom.com/sas-tips-tricks-4-note-query-specified-involves-ordering-item-doesnt-appear-select-clause/">statskom.com/sas-tips-tricks-5-/</a>) we looked at how to clean up the log by removing the &#8220;NOTE: Missing values were generated..&#8221; message. In this post we continue the theme by looking at another commonly occurring SAS message and how it can be resolved.</p>
<p>In this post we look at the SAS log message: &#8220;NOTE: Missing values were generated as a result of performing an operation on missing values.&#8221;, its causes and how to resolve it. This message is typically caused by attempting to perform a calculation on a numeric variable which is missing, its technical name is the propogation of missing values, since a missing input value causes a missing output value.</p>
<p>Consider the following vital signs data where we have three test results for pulse and two for heart rate.</p>
<pre>DATA vitals;
  ATTRIB pulse1 pulse2 pulse3 hr1 hr2 format = best.;
  INPUT pulse1 pulse2 pulse3 hr1 hr2;
INFILE cards;
DATALINES;
60 70 65 71 .
65 . 70 73 74
63 . . 72 73
65 77 73 74 75;
RUN;</pre>
<p>Notice that these test results are sometimes missing, now if we were to run a DATA Step similar to the below</p>
<pre>DATA vitals2;
  SET vitals;
  pulse_sum=pulse1+pulse2+pulse3;
  hr_sum = hr1 + hr2;
RUN;</pre>
<p>We would result in messages similar to the following being written to the SAS log:</p>
<p>79 DATA vitals2;<br />
80 SET vitals;<br />
81 pulse_sum=pulse1+pulse2+pulse3;<br />
82 hr_avg = (hr1 + hr2)/2;<br />
83 RUN;</p>
<p>NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column).  2 at 81:19 1 at 82:16</p>
<p>These messages tell you that the statement in line 81 of the log (81 pulse_sum=pulse1+pulse2+pulse3;) resulted in a missing values twice (2 at 81:19 )whereas the statement from line 82 (82 hr_avg = (hr1 + hr2;)/2 ) resulted in a missing value once (1 at 82:16) and a PROC PRINT of the results would show the following:</p>
<pre>Obs    pulse1    pulse2    pulse3    hr1   hr2    pulse_sum  hr_sum

1       60        70        65      71      .       195        .
2       65         .        70      73     74         .      73.5
3       63         .         .      72     73         .      72.5
4       65        77        73      74     75       215      74.5</pre>
<p>Note that as described in the log, the variable PULSE_SUM is missing twice (observations 2 and 3) whilse the HR_SUM variable is missing once (observation 1).</p>
<p>How you decide to deal with this message depends on whether you expect the variables in your input data to contain missing. If you do then you can omit missing values from your calculations by using the sample statistic functions. In this case we would use the MEAN and SUM functions as follows:</p>
<pre>DATA vitals2;
  SET vitals;
  pulse_sum=SUM(pulse1,pulse2,pulse3);
  hr_avg = MEAN(hr1,hr2);
RUN;</pre>
<p>Printing out the dataset gives the following:</p>
<pre>Obs    pulse1    pulse2    pulse3   hr1    hr2     pulse_sum  hr_avg

1       60        70        65      71      .       195      71.0
2       65         .        70      73     74       135      73.5
3       63         .         .      72     73        63      72.5
4       65        77        73      74     75       215      74.5</pre>
<p>Note that here PULSE_SUM is populated in every observation and is calculated as the sum of all available PULSE variables. HR_AVG is also populated in every observation and is calculated as the sum of all available HR variables divided by the number of available HR variables.</p>
<p>If however your data should not contain any missing values, then you could alternatively use the NMISS function to test whether your variables contain missing values and output a message to the log if they do.</p>
<p>More information on the mean and sum functions can be found in the <a href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245860.htm">Functions and Call Routines </a>section of the SAS doc</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-6-note-missing-values-generated-result-performing-operation-missing-values/">SAS tips &#038; tricks #6 – NOTE: Missing values were generated as a result of performing an operation on missing 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-6-note-missing-values-generated-result-performing-operation-missing-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #5 – NOTE: The query as specified involves ordering by an item that doesn&#8217;t appear in its SELECT clause</title>
		<link>http://statskom.com/sas-tips-tricks-4-note-query-specified-involves-ordering-item-doesnt-appear-select-clause/</link>
		<comments>http://statskom.com/sas-tips-tricks-4-note-query-specified-involves-ordering-item-doesnt-appear-select-clause/#comments</comments>
		<pubDate>Fri, 29 Aug 2014 14:59:48 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=286</guid>
		<description><![CDATA[<p>SQL allows the SAS programmer to write concise code and offers many advantages over the DATA step, however becoming over reliant on SQL can lead to problems. One issue we regularly see is the following message in the SAS log:&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-4-note-query-specified-involves-ordering-item-doesnt-appear-select-clause/">SAS tips &#038; tricks #5 – NOTE: The query as specified involves ordering by an item that doesn&#8217;t appear in its SELECT clause</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>SQL allows the SAS programmer to write concise code and offers many advantages over the DATA step, however becoming over reliant on SQL can lead to problems. One issue we regularly see is the following message in the SAS log:</p>
<p>NOTE: The query as specified involves ordering by an item that doesn&#8217;t appear in its SELECT clause.</p>
<p>A quick google search of this message returns several thousand hits suggesting it&#8217;s a common problem.</p>
<p>Some clients may find it acceptable to leave this message in the log, whereas others may require that it is removed. This message is most commonly caused by the user attempting to sort a dataset using a variable which will not appear in the final dataset or attempting to create a macro list from a specific variable but to order it using the values of another variable. In both instances the program should function as expected however the unsightly note will be present in the log.</p>
<p>Below we will look at how to avoid this message in  each of these instances:</p>
<p>Here is an example of some code which attempts to sort a dataset using code not present in the final dataset, this code would create the ordered output dataset as expected however &#8220;The query as specified &#8230;&#8221; note would be present in the log:</p>
<pre>PROC SQL;
  CREATE TABLE class  AS
  SELECT name 
  FROM sashelp.class
  ORDER BY sex;
QUIT;</pre>
<p>An efficient and concise way to prevent the NOTE being written to the log would be to use Data Set Options on the output table as follows:</p>
<pre>PROC SQL;
  CREATE TABLE class(DROP=sex)  AS
  SELECT name, sex 
  FROM sashelp.class
  ORDER BY sex;
QUIT;</pre>
<p>Here is an example of the some code which attempts to create a space separated macro list NAMELIST holding the values of the NAME variable ordered by the SEX variable. Again this code would work as expected, however the NOTE would be present in the log.</p>
<pre>PROC SQL;
  SELECT name INTO :namelist SEPARATED BY " "
  FROM sashelp.class
  ORDER BY sex;
QUIT;</pre>
<p>An efficient way to avoide this would be to first sort the data and then to use a DATA Step to create the list instead, for example using code similar to the below:</p>
<pre>PROC SORT DATA = sashelp.class OUT = class;
  BY sex;
RUN;

DATA _NULL_;
  LENGTH retain_var $1000;
  RETAIN retain_var ' ';
  SET class end=eof;
  IF _n_ = 1 THEN retain_var = STRIP(name);
  ELSE retain_var = STRIP(retain_var)||' '||STRIP(name);
  IF eof THEN CALL symput('namelist', retain_var);
RUN;
</pre>
<p>Please contact us if you have any SAS issues that you would like us to feature.</p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-4-note-query-specified-involves-ordering-item-doesnt-appear-select-clause/">SAS tips &#038; tricks #5 – NOTE: The query as specified involves ordering by an item that doesn&#8217;t appear in its SELECT clause</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-4-note-query-specified-involves-ordering-item-doesnt-appear-select-clause/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #4 – Visualising SAS datasets with an sql histogram</title>
		<link>http://statskom.com/sas-tips-tricks-4-visualising-datasets-sql-histogram/</link>
		<comments>http://statskom.com/sas-tips-tricks-4-visualising-datasets-sql-histogram/#comments</comments>
		<pubDate>Thu, 28 Aug 2014 14:52:18 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[histogram]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[PROC SQL]]></category>
		<category><![CDATA[SAS]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=276</guid>
		<description><![CDATA[<p>In our last post SAS tips &#38; tricks #3 – SAS dictionary tables, we looked at how the dictionary tables can be used to find metadata about the SAS session, including dataset and variable level metadata. In this post we&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-4-visualising-datasets-sql-histogram/">SAS tips &#038; tricks #4 – Visualising SAS datasets with an sql histogram</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In our last post <a title="SAS tips &amp; tricks #3 – SAS dictionary tables" href="http://statskom.com/sas-tips-tricks-3-sas-dictionary-tables/">SAS tips &amp; tricks #3 – SAS dictionary tables</a>, we looked at how the dictionary tables can be used to find metadata about the SAS session, including dataset and variable level metadata.</p>
<p>In this post we look at how we can use a simple piece of SQL to create a histogram which gives a quick overview of the number of variables in each domain.</p>
<p>The SASHELP.VCOLUMN dataset contains a list of all variables present in each dataset. Here we use the repeat function to output a &#8220;*&#8221; character for each variable in the dataset. The output of the query is printed to the active output destination.</p>
<pre>PROC SQL;
   SELECT memname  , REPEAT('*',nvar) AS freq
   FROM sashelp.vtable
   WHERE libname = "SASHELP";
 QUIT;</pre>
<p>The result is something similar to the below, which gives a quick insight into the number of variables in each dataset in the SASHELP library.</p>
<p><a href="http://statskom.com/wp-content/uploads/2014/08/sql_histogram_vars.jpg"><img class="alignnone size-full wp-image-284" alt="sql_histogram_vars" src="http://statskom.com/wp-content/uploads/2014/08/sql_histogram_vars.jpg" width="531" height="706" /></a></p>
<p>This SQL histogram technique has a wide varierty of other applications, for example here we use it to show the frequency of countries within each region in the SASHELP.DEMOGRAPHICS dataset.</p>
<p>&nbsp;</p>
<pre>PROC SQL;
  SELECT region , REPEAT('*',COUNT(*)) AS freq
  FROM sashelp.demographics
  GROUP BY region
  ORDER BY region;
QUIT;</pre>
<p><a href="http://statskom.com/wp-content/uploads/2014/08/sql_histogram_region.jpg"><img class="alignnone  wp-image-283" alt="sql_histogram_region" src="http://statskom.com/wp-content/uploads/2014/08/sql_histogram_region.jpg" width="673" height="117" /></a></p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-4-visualising-datasets-sql-histogram/">SAS tips &#038; tricks #4 – Visualising SAS datasets with an sql histogram</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-4-visualising-datasets-sql-histogram/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #3 – SAS dictionary tables</title>
		<link>http://statskom.com/sas-tips-tricks-3-sas-dictionary-tables/</link>
		<comments>http://statskom.com/sas-tips-tricks-3-sas-dictionary-tables/#comments</comments>
		<pubDate>Mon, 25 Aug 2014 19:20:24 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=264</guid>
		<description><![CDATA[<p>In SAS tips &#38; tricks #2 we looked at retrieving metadata within a datastep using the VARxx functions. Here we look at how the SAS dictionary tables can be used to retrieve SAS metadata. If you&#8217;ve ever wondered how to determine&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-3-sas-dictionary-tables/">SAS tips &#038; tricks #3 – SAS dictionary tables</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In <a title="SAS tips &amp; tricks #2 – Retrieving variable metadata within DATA Steps" href="http://statskom.com/sas-tips-tricks-2/">SAS tips &amp; tricks #2 </a>we looked at retrieving metadata within a datastep using the VARxx functions. Here we look at how the SAS dictionary tables can be used to retrieve SAS metadata.</p>
<p>If you&#8217;ve ever wondered how to determine which variables are present in a dataset, which titles have been set, what format is associated with a particular variable or which ODS destinations have been setup, the dictionary tables could be what you are looking for.</p>
<p>The dictionary tables are a collection of automatically available, read only, tables accessible via PROC SQL. For example, the following SQL clause would create a dataset containing variable level metaedata for the SASHELP.FLAGS dataset, which would include, amongst other things, a list of all the variables present in the dataset, their lengths, formats, informats and more.</p>
<pre>PROC SQL ;
  CREATE TABLE flag_var_meta AS
  SELECT * FROM
  dictionary.columns
  WHERE libname = "SASHELP" AND memname ="FLAGS" ;
QUIT;
</pre>
<p>Whereas the following code would create a dataset containing all TITLES and FOOTNOTES currently set within the session.</p>
<pre>
PROC SQL ;
 CREATETABLE title_meta AS
 SELECT * FROM
 dictionary.titles;
QUIT;
</pre>
<p>It&#8217;s easy to see how this information can be used to automate subsequent programming steps.</p>
<p>More information on the SAS dictionary tables is available in the <a title="SAS documentation" href="http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001385596.htm">SAS (R) online documentation: </a></p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-3-sas-dictionary-tables/">SAS tips &#038; tricks #3 – SAS dictionary tables</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-3-sas-dictionary-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS tips &amp; tricks #2 – Retrieving variable metadata within DATA Steps</title>
		<link>http://statskom.com/sas-tips-tricks-2/</link>
		<comments>http://statskom.com/sas-tips-tricks-2/#comments</comments>
		<pubDate>Sun, 02 Mar 2014 19:29:19 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[SAS]]></category>
		<category><![CDATA[SAS Functions]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=239</guid>
		<description><![CDATA[<p>In our last tips &#38; tricks blogpost we looked at how the VARNUM function could be used to within a DATA Step to determine whether a variable was present within dataset and how this function could be used as an&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-2/">SAS tips &#038; tricks #2 – Retrieving variable metadata within DATA Steps</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In our last <a title="SAS tips &amp; tricks #1 – The VARNUM function" href="http://statskom.com/sas-tips-tricks-1-the-varnum-function/">tips &amp; tricks blogpost </a>we looked at how the VARNUM function could be used to within a DATA Step to determine whether a variable was present within dataset and how this function could be used as an alternative to referencing  the dictionary tables or a PROC CONTENTS. Today we look at how the VARxx functions can be used in combination with the VARNUM function to determine other attributes about variables in a dataset.</p>
<p>The additional functions are shown in the table below and each can be used to retrieve a specific piece of metadata:</p>
<table border="0" align="center">
<tbody>
<tr>
<td style="border: 1px solid #000000;">VARFMT</td>
<td style="border: 1px solid #000000;">Returns the format that is assigned to a SAS data set variable.</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">VARINFMT</td>
<td style="border: 1px solid #000000;">Returns the informat that is assigned to a SAS data set variable.</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">VARLABEL</td>
<td style="border: 1px solid #000000;">Returns the label that is assigned to a SAS data set variable.</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">VARLEN</td>
<td style="border: 1px solid #000000;">Returns the label that is assigned to a SAS data set variable.</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">VARNAME</td>
<td style="border: 1px solid #000000;">Returns the length of a SAS data set variable.</td>
</tr>
<tr>
<td style="border: 1px solid #000000;">VARTYPE</td>
<td style="border: 1px solid #000000;">Returns the length of a SAS data set variable.</td>
</tr>
</tbody>
</table>
<p>The example below shows how to use VARTYPE and VARLEN functions to retrieve the type and length of variables.</p>
<pre><span style="font-size: small;"><strong><span style="color: #0000ff;">DATA </span></strong></span> <span style="color: #0000ff; font-family: Courier New;"><span style="color: #0000ff; font-family: Courier New;"><span style="color: #0000ff; font-family: Courier New;">_null_</span></span></span><span style="font-family: Courier New;"><span style="font-family: Courier New;">;
</span></span>  dsid=OPEN(<span style="color: #800080; font-family: Courier New;"><span style="color: #800080; font-family: Courier New;"><span style="color: #800080; font-family: Courier New;">"sashelp.class"</span></span></span><span style="font-family: Courier New;"><span style="font-family: Courier New;">);
  <span style="color: #0000ff;">CALL</span> SYMPUT("<span style="color: #800080;">name_length</span>",VARLEN(dsid,VARNUM(dsid,1));
</span></span><span style="color: #0000ff; font-family: Courier New;"><span style="color: #0000ff; font-family: Courier New;"><span style="color: #0000ff; font-family: Courier New;">  CALL</span></span></span><span style="font-family: Courier New;"><span style="font-family: Courier New;"> SYMPUTX(</span></span><span style="color: #800080; font-family: Courier New;"><span style="color: #800080; font-family: Courier New;"><span style="color: #800080; font-family: Courier New;">"height_type"</span></span></span><span style="font-family: Courier New;"><span style="font-family: Courier New;">,VARTYPE(dsid,VARNUM(dsid,</span></span><span style="color: #800080; font-family: Courier New;"><span style="color: #800080; font-family: Courier New;"><span style="color: #800080; font-family: Courier New;">"height"</span></span></span><span style="font-family: Courier New;"><span style="font-family: Courier New;">)));
</span></span><strong><span style="color: #0000ff;">RUN</span></strong><span style="font-family: Courier New;"><span style="font-family: Courier New;">;

</span></span></pre>
<p>Note that in the VARLEN statement we specify the column number of the variable we are interested in. In the VARTYPE example we retrieve the column number by first using the VARNUM function.</p>
<p>All of these functions appear under the SAS SAS File I/O Category. More information about these functions is available within the <a title="SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition" href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245860.htm">SAS (R) Language Reference: Dictionary </a></p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-2/">SAS tips &#038; tricks #2 – Retrieving variable metadata within DATA Steps</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
