<?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>Dammit Jim! &#187; code</title>
	<atom:link href="http://scott.sherrillmix.com/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Mon, 06 Feb 2012 05:19:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Syntax highlighting in terminal</title>
		<link>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:53:09 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[pygmentize]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=526</guid>
		<description><![CDATA[I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using head or grep without having to open an editor. Luckily, I remembered Pygmentize was pretty handy when syntax highlighting in LaTeX so I wondered if they had [...]]]></description>
			<content:encoded><![CDATA[<img src="/res/images/ccat.png" alt="Syntax highlighted cat" class="right"/>
<p>I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using <code>head</code> or <code>grep</code> without having to open an editor. Luckily, I remembered <a href="http://pygments.org/">Pygmentize</a> was pretty handy when <a href="http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/">syntax highlighting in LaTeX</a> so I wondered if they had an equivalent output for terminal. It turns out they do (in standard or 256 color no less) so in a couple minutes I had a really short script for highlighting code at the terminal saved it to <code>bin/ccat</code> and was ready to go. Pygmentize really is impressive. Here's the script if anyone else is looking to do the same:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-2">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/bin/bash#!/bin/bash</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> ! -t <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>/dev/stdin</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">elif</span> <span style="color: #66cc66;">&#91;</span> -f $<span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>$<span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"Usage: $0 code.c"</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"or e.g. head code.c|$0"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">exit</span> <span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">fi</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pygmentize -f terminal -g <span style="color: #0000ff;">$file</span> </div></li></ol></div>
</div></div><br />
<p>It just looks for stdin and if it doesn't find it it looks for a file name or takes direct input. Obviously it requires Pygmentize (which is really <a href="http://pygments.org/download/">easy to install</a> if you already have Python).</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Displaying Code in LaTeX</title>
		<link>http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 06:28:37 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[#]]></category>
		<category><![CDATA[anglesign]]></category>
		<category><![CDATA[appendix]]></category>
		<category><![CDATA[bnb]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[equation box]]></category>
		<category><![CDATA[hfill]]></category>
		<category><![CDATA[M^2]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[verbatim]]></category>
		<category><![CDATA[\alpha_i]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=437</guid>
		<description><![CDATA[gioby of Bioinfo Blog! (an interesting read by the way) left a comment asking about displaying code in LaTeX documents. I've sort of been cludging around using \hspace's and \textcolor but I've always meant to figure out the right way to do things so this seemed like a good chance to figure out how to [...]]]></description>
			<content:encoded><![CDATA[<p>gioby of <a href='http://bioinfoblog.it/'>Bioinfo Blog!</a> (an interesting read by the way) left a comment asking about displaying code in LaTeX documents. I've sort of been cludging around using <code>\hspace</code>'s and <code>\textcolor</code> but I've always meant to figure out the right way to do things so this seemed like a good chance to figure out how to do it right.</p>

<p>LaTeX tends to ignore white space. This is good when you're writing papers but not so good when you're trying to show code where white space is an essential part (e.g. Python). Luckily there's a builtin <code>verbatim</code> environment in LaTeX that is equivalent to html's <code>&lt;pre&gt;</code>. So something like the following should preserve white space.</p>
<img src="/res/images/latex_verbatim.png" alt="Code in LaTeX using verbatim" class="right"/><pre><code>\begin{verbatim}
for i in range(1, 5):
  print i
else:
  print &quot;The for loop is over&quot;
\end{verbatim}</code></pre>

<p>Unfortunately, you can't use any normal LaTeX commands inside verbatim (since they're displayed <em>verbatim</em>). But luckily there a handy package called <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/">fancyvrb</a> that fixes this (the <a href="http://www.ctan.org/tex-archive/help/Catalogue/entries/color.html">color</a> package is also useful for adding colors). For example, if you wanted to highlight "for" in the above code, you can use the <code>Verbatim</code> (note the capital V) environment from fancyvrb:</p>
<img src="/res/images/latex_fancyvrb.png" alt="Code in LaTeX using fancyvrb" class="right"/>
<pre><code>\newcommand\codeHighlight[1]{\textcolor[rgb]{1,0,0}{\textbf{#1}}}
\begin{Verbatim}[commandchars=\\\{\}]
\codeHighlight{for} i in range(1, 5):
  print i
else:
  print &quot;The for loop is over&quot;
\end{Verbatim}
</code></pre>

<img src="/res/images/latex_pygmentize.png" alt="Code in LaTeX using pygmentize" class="right"/>
<p>If you really want to get fancy, the <a href='http://pygments.org/docs/quickstart/'>Pygments package</a> in Python will output syntax highlighted latex code with a command like: <code>pygmentize -f latex -O full test.py &gt;py.tex</code> The LaTeX it outputs is a bit hard to read but it's not too bad (it helped me figure out the fancyvrb package) and it does make nice syntax highlighted output.</p>

<p>Here's an example LaTeX file with the three examples above and the pdf it generates if you're curious.</p>
<ul>
<li><a href="/res/codeInLatex.tex">codeInLatex.tex</a></li>
<li><a href="/res/codeInLatex.pdf">codeInLatex.pdf</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How SINs (and Credit Card Numbers) Are Validated</title>
		<link>http://scott.sherrillmix.com/blog/programmer/how-sins-and-credit-card-numbers-are-validated/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/how-sins-and-credit-card-numbers-are-validated/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 15:53:05 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[999999998]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[credit card]]></category>
		<category><![CDATA[Luhn algorithm]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[SIN]]></category>
		<category><![CDATA[validate]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=356</guid>
		<description><![CDATA[A while back it was tax season in Canada and a friend of mine was trying to do his taxes online. But since he was foreign and didn't have a Social Insurance Number (their equivalent of an SSN), the helpful webapp wouldn't let him print the thing (of course it only informed him of that [...]]]></description>
			<content:encoded><![CDATA[<p>A while back it was tax season in Canada and a friend of mine was trying to do his taxes online. But since he was foreign and didn't have a Social Insurance Number (their equivalent of an SSN), the helpful webapp wouldn't let him print the thing (of course it only informed him of that after he had already entered everything). We tried a few guesses before finally just using mine and crossing out my numbers after printing it. But I always wondered how the form knew our guesses were invalid. Luckily, I recently stumbled across a <a href="http://www.marksanborn.net/php/validating-credit-card-numbers-with-zend-framework/">mention of how credit card numbers are validated</a>.</p>
<p>It turns out SINs and credit card number are checked with something called the <a href="http://en.wikipedia.org/wiki/Luhn_algorithm">Luhn algorithm</a>. Basically the algorithm just involves taking each digit, multiplying the second, fourth, sixth and so on digit from the right by 2 and adding up all the resulting <em>digits</em> (e.g. if 7 is multiplied by 2 then the resulting 14 is split into 1+4). If the sum of the digits is a multiple of 10, the number passes.</p>
<p>For example, to check 345678, you'd split it into 3,4,5,6,7,8. Then multiply 3, 5 and 7 by 2 to give 6, 4, 10, 6, 14, 8. Then split all the digits again to give 6, 4, 1, 0, 6, 1, 4, 8. That adds up to 30 so 345678 would be a valid credit card number (if there wasn't a set length).</p>
<p>Just for fun, here's a quick function in R to run the Luhn Algorithm on a number (or tell you the remainder so you can adjust):</p>
<div class="syntax_hilite"><span class="langName">R:</span><br /><div id="r-4">
<div class="r"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">luhnCheck &lt;- <span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>number,returnLogical=<span style="color:#228b22;">TRUE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; numbers &lt;- gsub<span style="color: #66cc66;">&#40;</span>'<span style="color: #66cc66;">&#91;</span>^<span style="color: #cc66cc;color:#800000;">0</span>-<span style="color: #cc66cc;color:#800000;">9</span><span style="color: #66cc66;">&#93;</span>','',as.character<span style="color: #66cc66;">&#40;</span>number<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; numbers &lt;- as.numeric<span style="color: #66cc66;">&#40;</span>strsplit<span style="color: #66cc66;">&#40;</span>numbers,''<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; selector&lt;-seq<span style="color: #66cc66;">&#40;</span>length<span style="color: #66cc66;">&#40;</span>numbers<span style="color: #66cc66;">&#41;</span>-<span style="color: #cc66cc;color:#800000;">1</span>,<span style="color: #cc66cc;color:#800000;">1</span>,-<span style="color: #cc66cc;color:#800000;">2</span><span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; numbers<span style="color: #66cc66;">&#91;</span>selector<span style="color: #66cc66;">&#93;</span>&lt;-numbers<span style="color: #66cc66;">&#91;</span>selector<span style="color: #66cc66;">&#93;</span>*<span style="color: #cc66cc;color:#800000;">2</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; numbers<span style="color: #66cc66;">&#91;</span>numbers&gt; <span style="color: #cc66cc;color:#800000;">9</span><span style="color: #66cc66;">&#93;</span> &lt;- numbers<span style="color: #66cc66;">&#91;</span>numbers&gt; <span style="color: #cc66cc;color:#800000;">9</span><span style="color: #66cc66;">&#93;</span> - <span style="color: #cc66cc;color:#800000;">9</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; remainder &lt;- sum<span style="color: #66cc66;">&#40;</span>numbers<span style="color: #66cc66;">&#41;</span> %% <span style="color: #cc66cc;color:#800000;">10</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #a020f0;">if</span><span style="color: #66cc66;">&#40;</span>returnLogical<span style="color: #66cc66;">&#41;</span> <span style="color: #a020f0;">return</span><span style="color: #66cc66;">&#40;</span>remainder==<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #a020f0;">else</span> <span style="color: #a020f0;">return</span><span style="color: #66cc66;">&#40;</span>remainder<span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div></li></ol></div>
</div></div><br />
<p>So the next time some stupid web form needs a SIN number I'm going with 999999998.</p>
]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/how-sins-and-credit-card-numbers-are-validated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAS Macros: Letting SAS Do the Typing</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-macros-letting-sas-do-the-typing/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/sas-macros-letting-sas-do-the-typing/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 08:09:31 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[SAS]]></category>
		<category><![CDATA[Statistician]]></category>
		<category><![CDATA[ampersand]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[do loop]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[syput]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-macros-letting-sas-do-the-typing/</guid>
		<description><![CDATA[I've been meaning to write up a bit on using macros in SAS to complement my previous post on macro variables for quite a while. Luckily Norwegian guy reminded me about the pain of starting programming in SAS and provided me some motivation. So here's my take on using macros in programming. So what is [...]]]></description>
			<content:encoded><![CDATA[<p>I've been meaning to write up a bit on using macros in SAS to complement my previous post on <a href="http://scott.sherrillmix.com/blog/programmer/sas-macros/">macro variables</a> for quite a while. Luckily <a href="http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comment-14002">Norwegian guy</a> reminded me about the pain of starting programming in SAS and provided me some motivation. So here's my take on using macros in programming.</p>

<p>So what is a macro? Macros are a part of SAS that look through your code before the normal part of SAS sees it and writes out your code for you based on a special syntax. If you've ever found yourself copying and pasting code then you've probably been in a situation well suited for macros. They're also great if you need to perform different functions under different conditions. Once I learned macros, SAS seemed a lot more like a usable (although weird) programming language and tasks seemed to get a lot easier (except actually picking the statistical techniques to use).</p>

<p>Probably the easiest way to see what macros do is an example. So say we once again have a data set of tree heights</p>

<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-12">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">data</span> trees;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">input</span> name:$<span style="color: #2e8b57; font-weight: bold;color:#800000;">8</span>. height;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">cards;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Maple <span style="color: #2e8b57; font-weight: bold;color:#800000;">123</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Maple <span style="color: #2e8b57; font-weight: bold;color:#800000;">78</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Maple <span style="color: #2e8b57; font-weight: bold;color:#800000;">90</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Elm <span style="color: #2e8b57; font-weight: bold;color:#800000;">155</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Elm <span style="color: #2e8b57; font-weight: bold;color:#800000;">65</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Elm <span style="color: #2e8b57; font-weight: bold;color:#800000;">90</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Elm <span style="color: #2e8b57; font-weight: bold;color:#800000;">120</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Birch <span style="color: #2e8b57; font-weight: bold;color:#800000;">100</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Birch <span style="color: #2e8b57; font-weight: bold;color:#800000;">30</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Maple <span style="color: #2e8b57; font-weight: bold;color:#800000;">111</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">run</span>; </div></li></ol></div>
</div></div><br />

<p>I already talked about how to find and use the mean and standard deviation for the <a href="http://scott.sherrillmix.com/blog/programmer/sas-macros/"> whole data set</a>. Now what if we wanted to standardize each species by its own seperate mean and deviation? We could cut and paste but once we get a few more species or want to change something later this really becomes a hassle. So this is where macros come in.</p>

<p>The first thing to do is to calculate the mean and standard deviations for each species. We can use <code>proc means</code> again to do this. Since we won't be using the output I'll add the <code>noprint</code> option and since we only want the means for the individual species and not the whole dataset I'll add the <code>nway</code> option. The <code>class name;</code> statement tells SAS to find the statistics seperately for each species and the <code>output</code> line tells SAS to save the mean and deviation in a dataset called <code>meansd</code>.</p>
<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-13">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">proc means</span> <span style="color: #000080; font-weight: bold;">data</span>=trees nway noprint;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">class name;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">var</span> height;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">output</span> out=meansd <span style="color: #0000ff;">mean</span>=meanheight <span style="color: #0000ff;">std</span>=sdheight;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">run</span>; </div></li></ol></div>
</div></div><br />

<p>Now we just need to get the values from the <code>meansd</code> dataset into macro variables. We'll use the _NULL_ dataset and <code>call symput</code> again to create macro variables. This time we need to create seperate macro variables for each species. Luckily SAS automatically numbers each observation in a dataset in a column called <code>_N_</code>. Since each line of the dataset corresponds to a tree species, we can easily use this identifier to create the macro variables by using <code>call symput(&#039;mean&#039;||left(_N_), meanheight);</code>. The <code>left()</code> and <code>()trim</code> functions (numeric variables have extra spaces to the left and string variables have spaces to the right) removes any unnecessary spaces and the <code>||</code> concatenates (connects) the text "mean" with the line number to give give <code>mean1</code>, <code>mean2</code>, etc.. I'll do the same thing for standard deviation and tree name. Once the macro variables are created, there is still one problem remaining. We don't know how many species there were or how many macro variables were created. Luckily SAS will make another column that indicates the last line of the dataset when it sees <code>end=newcolumnname</code> following a set statement. Then we just need to check if SAS is on the last line and if so save the line number (<code>_N_</code>) to know the number of species of trees.</p>  

<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-14">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">data</span> <span style="color: #0000ff;">_NULL_</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">set</span> meansd <span style="color: #0000ff;">end</span>=last;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">call</span> symput<span style="color: #66cc66;">&#40;</span><span style="color: #a020f0;">'mean'</span>||left<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">_N_</span><span style="color: #66cc66;">&#41;</span>,meanheight<span style="color: #66cc66;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">call</span> symput<span style="color: #66cc66;">&#40;</span><span style="color: #a020f0;">'sd'</span>||left<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">_N_</span><span style="color: #66cc66;">&#41;</span>,sdheight<span style="color: #66cc66;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">call</span> symput<span style="color: #66cc66;">&#40;</span><span style="color: #a020f0;">'name'</span>||left<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">_N_</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #0000ff;">trim</span><span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">if</span> last <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">call</span> symput<span style="color: #66cc66;">&#40;</span><span style="color: #a020f0;">'numspecies'</span>,<span style="color: #0000ff;">_N_</span><span style="color: #66cc66;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">run</span>; </div></li></ol></div>
</div></div><br />

<p>If you ever want to check what macro variables you have in your program, you can use <code>%PUT _USER_;</code> to print them all to the log file. Or if you want to see every macro variable available  (SAS has quite a few automatic ones like operating system and date) use <code>%PUT _ALL_;</code>. Inserting <code>%PUT _USER_;</code> here produces:</p>
<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-15">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL NUMSPECIES&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">3</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL NAME1 Birch</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL NAME2 Elm</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL NAME3 Maple</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL MEAN1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">65</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL MEAN2&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">107</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">5</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL MEAN3&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">100</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">5</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL SD1 <span style="color: #2e8b57; font-weight: bold;color:#800000;">49</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">497474683</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL SD2 <span style="color: #2e8b57; font-weight: bold;color:#800000;">38</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">837267326</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GLOBAL SD3 <span style="color: #2e8b57; font-weight: bold;color:#800000;">20</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">273134933</span> </div></li></ol></div>
</div></div><br />
<p>Now we've set a lot of macro variables but we still haven't created a real macro. In SAS, macros are started with <code>%MACRO macroname;</code> and finished with <code>%MEND;</code> (short for M[acro]END). <code>%</code>'s are used to indicate commands that the SAS macro facility will read and remove before normal SAS sees the code. Anything not with a % will be printed out by the macro facility. Macros don't spit out their code for SAS until they're are called using <code>%macroname</code>.</p>

<p>So I'll call my macro <code>treestandardizer</code> but you can call it whatever you want. I'm going to use a pretty simple and specific macro but if you were going to use this often and for different datasets you would want to program it better. The first thing to do is create the <code>final</code> dataset and set it to the <code>trees</code> dataset. Since we need to loop through each species of tree, we'll need a <code>%DO</code> loop. Everything between <code>%DO</code> and <code>%END</code> will be repeated while <code>i</code> increments from 1 to the number of tree species.  If you want to combine text and a macro variable to reference another macro variable, you use the double ampersand <code>&amp;&amp;<!--formatted--></code> in SAS. For example, we want to get the mean for species 1 by looking in the macro variable <code>&amp;mean1<!--formatted--></code> so we use <code>&amp;&amp;mean&amp;i<!--formatted--></code>. I <em>think</em> the macro processing part of SAS ends up running through the code twice, the first time finding the <code>&amp;&amp;<!--formatted--></code> and replacing it with <code>&amp;<!--formatted--></code> and the <code>&amp;i<!--formatted--></code> and replacing it with <code>1</code> to leave <code>&amp;mean1<!--formatted--></code> and the second time finding <code>&amp;mean1<!--formatted--></code> and pasting in the appropriate value (65). So we'll have the do loop write out a series of <code>if</code> statements to check what the name of the tree is and use the appropriate mean and deviation. Note that when using a string macro variable like <code>&amp;nameX<!--formatted--></code>, you need to surround it with double quotes (the macro processor doesn't look inside single quotes) so SAS doesn't think it is a variable name. </p>

<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-16">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">%MACRO</span> treestandardizer;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">data</span> final;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">set</span> trees;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">%DO</span> i = <span style="color: #2e8b57; font-weight: bold;color:#800000;">1</span> <span style="color: #0000ff;">%TO</span> <span style="color: #0000ff; font-weight: bold;">&amp;numspecies</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">if</span> name=<span style="color: #a020f0;">"&amp;&amp;name&amp;i"</span> <span style="color: #0000ff;">then</span> stheight=<span style="color: #66cc66;">&#40;</span>height-&amp;<span style="color: #0000ff; font-weight: bold;">&amp;mean</span><span style="color: #0000ff; font-weight: bold;">&amp;i</span><span style="color: #66cc66;">&#41;</span>/&amp;<span style="color: #0000ff; font-weight: bold;">&amp;sd</span><span style="color: #0000ff; font-weight: bold;">&amp;i</span>; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">%END</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000080; font-weight: bold;">run</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">%MEND</span>; </div></li></ol></div>
</div></div><br />

<p>The previous code prepared the macro but nothing actually happens until we call it using <code>%treestandardizer</code>. Unlike almost everything else in SAS this line doesn't have to end in a semicolon (although it's pretty unlikely to hurt if you forget and add one). So to call the macro:</p>
<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-17">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">%treestandardizer </div></li></ol></div>
</div></div><br />

<p>If you want to see what happens when you call a macro, you can have SAS print the code generated by the macro to the log file with the option <code>option mprint;</code> (make sure to set it before actually calling the macro). In this case, it gives:</p>
<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-18">
<div class="sas"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MPRINT<span style="color: #66cc66;">&#40;</span>TREESTANDARDIZER<span style="color: #66cc66;">&#41;</span>:&nbsp; &nbsp;<span style="color: #000080; font-weight: bold;">data</span> final;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MPRINT<span style="color: #66cc66;">&#40;</span>TREESTANDARDIZER<span style="color: #66cc66;">&#41;</span>:&nbsp; &nbsp;<span style="color: #0000ff;">set</span> trees;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MPRINT<span style="color: #66cc66;">&#40;</span>TREESTANDARDIZER<span style="color: #66cc66;">&#41;</span>:&nbsp; &nbsp;<span style="color: #0000ff;">if</span> name=<span style="color: #a020f0;">"Birch"</span> <span style="color: #0000ff;">then</span> stheight=<span style="color: #66cc66;">&#40;</span>height- <span style="color: #2e8b57; font-weight: bold;color:#800000;">65</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #2e8b57; font-weight: bold;color:#800000;">49</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">497474683</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MPRINT<span style="color: #66cc66;">&#40;</span>TREESTANDARDIZER<span style="color: #66cc66;">&#41;</span>:&nbsp; &nbsp;<span style="color: #0000ff;">if</span> name=<span style="color: #a020f0;">"Elm"</span> <span style="color: #0000ff;">then</span> stheight=<span style="color: #66cc66;">&#40;</span>height- <span style="color: #2e8b57; font-weight: bold;color:#800000;">107</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">5</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #2e8b57; font-weight: bold;color:#800000;">38</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">837267326</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">MPRINT<span style="color: #66cc66;">&#40;</span>TREESTANDARDIZER<span style="color: #66cc66;">&#41;</span>:&nbsp; &nbsp;<span style="color: #0000ff;">if</span> name=<span style="color: #a020f0;">"Maple"</span> <span style="color: #0000ff;">then</span> stheight=<span style="color: #66cc66;">&#40;</span>height- <span style="color: #2e8b57; font-weight: bold;color:#800000;">100</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">5</span><span style="color: #66cc66;">&#41;</span>/<span style="color: #2e8b57; font-weight: bold;color:#800000;">20</span>.<span style="color: #2e8b57; font-weight: bold;color:#800000;">273134933</span>; </div></li></ol></div>
</div></div><br />

<p>So it worked and we now have the standardized heights in the <code>stheight</code> column of the <code>final</code> dataset. This particular example could be done a few different ways (the easiest and probably better way being to merge the <code>meancv</code> dataset with the <code>trees</code>) but I hope it gives a decent introduction to SAS macros. If you have any specific questions or something wasn't clear, feel free to ask in a comment.</p> 

<p>Here is the <a href="/res/SAS_macro_example.sas">SAS source code</a> if you don't feel like copying and pasting.</p>

]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/sas-macros-letting-sas-do-the-typing/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>WP_CodeShield</title>
		<link>http://scott.sherrillmix.com/blog/blogger/wp_codeshield/</link>
		<comments>http://scott.sherrillmix.com/blog/blogger/wp_codeshield/#comments</comments>
		<pubDate>Mon, 14 May 2007 13:31:06 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Blogger]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[codeshield]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[htmlspecialchar]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plug in]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/wp_codeshield/</guid>
		<description><![CDATA[I've been burned a few times in WordPress when posting something like: This is how you make text italic: This is italic. when I actually wanted: This is how you make text italic: &#60;em&#62;This is italic.&#60;/em&#62; Of course it's not too hard to remember to encode the special characters but this is WordPress and things [...]]]></description>
			<content:encoded><![CDATA[<p>I've been burned a few times in WordPress when posting something like:</p>
<blockquote><p>This is how you make text italic: <code ><em>This is italic.</em></code ></p></blockquote>
<p>when I actually wanted:</p>
<blockquote><p>This is how you make text italic: <code>&lt;em&gt;This is italic.&lt;/em&gt;<!--formatted--></code></p></blockquote>
<p>Of course it's not too hard to remember to encode the special characters but this is WordPress and things are supposed to be easy. So I thought I would throw together a simple WordPress plugin to convert HTML special characters inside <code>&lt;code&gt;&lt;/code&gt;<!--formatted--></code> tags. That was a few months ago and I got the plugin most of the way done and then got distracted with other things. But after reading about <a href="http://wordlog.com/archives/2007/05/13/displaying-html-source-code-in-your-blog-posts/">another person having the same annoyance</a>, I decided I should finish the plugin.</p>

<p>So here is WP_CodeShield. It simply looks for <code>&lt;code&gt;&lt;/code&gt;<!--formatted--></code> tags in posts and comments and makes sure the contents are encoded properly. You just type the code you want inside <code>&lt;code&gt;&lt;/code&gt;<!--formatted--></code> tags and it should appear correctly. So you can type <code>&lt;code&gt;&lt;em&gt;This is italic.&lt;/em&gt;&lt;/code&gt;<!--formatted--></code> instead of <code>&lt;code&gt;&amp;lt;em&amp;gt;This is italic.&amp;lt;/em&amp;gt;&lt;/code&gt;<!--formatted--></code>.</p>
<p>If you have any questions, suggestions or requests, please leave them in the comments below. You can also test WP_CodeShield out in the comments if you are curious.</p>

<h3>Current Version:</h3> <p><a href="http://downloads.wordpress.org/plugin/wp-codeshield.zip">WP_CodeShield v0.4</a></p>

<h3>Installation instructions:</h3> <p>Unzip <code>wp_codeshield.zip</code>. Upload <code>wp_codeshield.php</code> to <code>wp-content/plugins/</code> and active in the Plugin Control Panel. That's it. Anything inside <code>&lt;code&gt;&lt;/code&gt;<!--formatted--></code> tags will now automatically be converted to proper HTML.</p>

<h3>Technical Details</h3>
<p>Most people should be OK just using WP_CodeShield naturally but for especially fancy users here are the more technical details:<br/> Nested code tags are ok (I've been using them in this post) but unequal numbers of <code>&lt;code&gt;<!--formatted--></code> and <code>&lt;/code&gt;<!--formatted--></code> will cause the plugin to leave the entire post or comment alone. WP_CodeShield will leave any string which already contains HTML special characters alone. For example <code>&amp;lt;em&amp;gt;<!--formatted--></code> will be left alone. This is in case you have previously hand entered the special characters or want to describe something more complex than the plugin can handle. To keep track of these special occurrences, WP_CodeShield adds a small invisible comment tag (<code>&lt;!--formatted--&gt;<!--formatted--></code>). WP_CodeShield only looks for <code>&lt;code&gt;&lt;/code&gt;<!--formatted--></code> tags. <code>&lt;code &gt;&lt;/code &gt;<!--formatted--></code> or <code>&lt;code class="fancy"&gt;&lt;/code&gt;<!--formatted--></code> will not be filtered. One small gotcha is that if a post contains <code>&lt;code class="fancy"&gt;&lt;/code&gt;<!--formatted--></code> no filtering will occur on that post (WP_CodeShield will think that the tags are unbalanced). You can get around this by making sure both the opening and closing tags do not match WP_CodeShield's target like <code>&lt;code class="fancy"&gt;&lt;/code &gt;<!--formatted--></code> (the extra space keeps WP_CodeShield from seeing the tags but are still valid HTML). </p> 


<h3>Change Log:</h3>
<ul>
<li><a href="/res/wp_codeshield_v0.4.zip">v0.4</a> 02-04-2008:
<ul>
<li>Changed filter to match updated wordpress <code>the_editor_content</code></li>
</ul>
</li>
<li><a href="/res/wp_codeshield_v0.3.zip">v0.3</a> 2-26-2007:
<ul>
<li>Properly converts when saving and unconverts when editing</li>
<li>Doesn't convert contents that are already encoded</li>
<li>Corrected wordpress hooks</li>
</ul>
</li>
<li>v0.2 2-26-2007:
<ul>
<li>Allows nested codes</li>
</ul>
</li>
<li>v0.1 2-13-2007:
<ul>
<li>A rough filter</li>
</ul>
</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/blogger/wp_codeshield/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>

