<?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-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 #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>
		<item>
		<title>SAS tips &amp; tricks #1 – The VARNUM function</title>
		<link>http://statskom.com/sas-tips-tricks-1-the-varnum-function/</link>
		<comments>http://statskom.com/sas-tips-tricks-1-the-varnum-function/#comments</comments>
		<pubDate>Fri, 21 Feb 2014 19:55:39 +0000</pubDate>
		<dc:creator><![CDATA[Andrew N]]></dc:creator>
				<category><![CDATA[SAS Tips & Tricks]]></category>
		<category><![CDATA[DICTIONARY TABLES]]></category>
		<category><![CDATA[PROC CONTENTS]]></category>
		<category><![CDATA[SAS]]></category>
		<category><![CDATA[VARNUM]]></category>

		<guid isPermaLink="false">http://statskom.com/?p=214</guid>
		<description><![CDATA[<p>A couple of well known ways to tell whether a variable is present in a dataset  include using a PROC CONTENTS or by referring to the SASHELP.VCOLUMN Dictionary Table, a perhaps lesser known approach is to utilise the VARNUM function.&#8230; </p><p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-1-the-varnum-function/">SAS tips &#038; tricks #1 – The VARNUM function</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: medium;">A couple of well known ways to tell whether a variable is present in a dataset  include using a PROC CONTENTS or by referring to the SASHELP.VCOLUMN Dictionary Table, a perhaps lesser known approach is to utilise the VARNUM function.</span></p>
<p><span style="font-size: medium;">The VARNUM function returns the number of a variable’s position within a dataset, or 0 if a variable is not present in a dataset. This value can then be used to control subsequent processing steps, for example,  only executing steps if a particular variable is present in a given dataset.</span></p>
<p><span style="font-size: medium;">The function is used in combination with the OPEN function as shown below.</span></p>
<p><span style="font-size: medium;">In this example we test to see whether the variable HEIGHT exists in the SASHELP.CLASS dataset. The variable is the fourth column within the dataset and so the function returns the value 4. In our example we’ve assigned this value to the macro variable HEIGHT_EXIST, so that it is readily available in subsequent steps.</span></p>
<blockquote>
<pre><span style="color: #888888;"><b>DATA</b> </span>_null_;
  dsid=OPEN("sashelp.class");
  CALL SYMPUTX("height_exist",VARNUM(dsid,"height"));
<b>RUN</b>;</pre>
</blockquote>
<p><span style="font-size: medium;">The VARNUM function can also be used in combination with other functions, for example VARTYPE and VARLABEL to gain additional information about the attributes of a variable.  </span></p>
<p><span style="font-size: medium;">See how in our next SAS Tips &amp; Tricks blog.</span></p>
<p>The post <a rel="nofollow" href="http://statskom.com/sas-tips-tricks-1-the-varnum-function/">SAS tips &#038; tricks #1 – The VARNUM function</a> appeared first on <a rel="nofollow" href="http://statskom.com">Statskom</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://statskom.com/sas-tips-tricks-1-the-varnum-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
