<?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-functions/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 #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>
