<?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; problem</title>
	<atom:link href="http://scott.sherrillmix.com/blog/tag/problem/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>Converting .eps to .png Easily</title>
		<link>http://scott.sherrillmix.com/blog/programmer/converting-eps-to-png-easily/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/converting-eps-to-png-easily/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 00:11:35 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[black]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[eps]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[jpg]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=303</guid>
		<description><![CDATA[I end up generating a lot of postscript plots in R and other programs. Unfortunately, a lot of not so technical people have trouble opening postscript files so I end up having to convert these images to other formats pretty often. A really handy program for converting eps files to png (or jpg although that's [...]]]></description>
			<content:encoded><![CDATA[<p>I end up generating a lot of postscript plots in R and other programs. Unfortunately, a lot of not so technical people have trouble opening postscript files so I end up having to convert these images to other formats pretty often. A really handy program for converting eps files to png (or jpg although that's not really an optimal format for plots) is <a href='http://www.imagemagick.org/'>ImageMagick</a> (available for all OSs I believe). ImageMagick lets you quickly convert (and <a href='http://www.imagemagick.org/Usage/'>create thumbnails, make B&#038;W,...</a>) from the command line without having to open up Photoshop.</p>
<p>For example, to convert an image named myPlot.eps to png you just need to enter <code>convert myPlot.eps myPlot.png</code> (convert is a program in the ImageMagick package) at the command prompt and you'll get a png file in myPlot.png. If you want to adjust the resolution (the default resolution is 72 dpi) of the output image, you can add the <code>-density</code> option (e.g. for 200 dpi <code>convert -density 200 myPlot.eps myPlot.png</code>). Make sure you put the <code>-density</code> part before the input image name.</p>
<p>Converting many files at once is where ImageMagick really shines. The <code>mogrify</code> command is probably the quickest option. For example, to convert the files image01.eps, image02.eps and image03.eps to png, just use the command <code>mogrify -format png image*.eps</code>. In one shot, it will create image01.png, image02.png and image03.png.</p> 

<p>Unfortunately, recent version of Imagemagick seem to be treating eps to png conversions oddly (see below) so mogrify isn't cutting it on my files. If you have similar trouble (and you're on Unix or Mac or Cygwin), you can just use a bit of Bash combined with the <code>convert</code> command to get around the problem like this:</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: #b1b100;">for</span> f <span style="color: #b1b100;">in</span> `ls *.eps`; <span style="color: #b1b100;">do</span> </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;convert -density <span style="color: #cc66cc;color:#800000;">100</span> <span style="color: #0000ff;">$f</span> -flatten $<span style="color: #66cc66;">&#123;</span>f%.*<span style="color: #66cc66;">&#125;</span>.png;</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: #b1b100;">done</span> </div></li></ol></div>
</div></div><br />

<h4>Black Background Problem</h4>
<p>As I mentioned above, I started having trouble converting from eps to png after upgrading to ImageMagick 6.4. The transparent/white backgrounds in my eps files were being converted to black backgrounds and making the figures unreadable. I guess it must be some change in how transparency is handled but I'm not totally sure what changed. It took me a bit of googling before I found the <a href='http://www.nabble.com/Background-issue-converting-.eps-to-.png-td20094851.html'>solution</a>, so I'll repost it here. Adding <code>-flatten</code> to the command (e.g. <code>convert myImage.eps -flatten myImage.png</code>) should change the background back to white. My <code>mogrify</code> command doesn't include the <code>-flatten</code> option so <code>convert</code> (like the example above) seems like the way to go.</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/converting-eps-to-png-easily/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>SAS lag problems</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comments</comments>
		<pubDate>Wed, 27 Sep 2006 23:07:23 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[SAS]]></category>
		<category><![CDATA[Statistician]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[caution]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[if statement]]></category>
		<category><![CDATA[lag]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/</guid>
		<description><![CDATA[I just found an interesting (that's interesting in the 'I just spent an hour debugging that?' sense) characteristic in SAS. If you have a variable, x, and are using the lag of x, do NOT put the lag(x) inside a conditional statement. This can apparently cause some pretty strange results. It is probably easier to [...]]]></description>
			<content:encoded><![CDATA[<p>I just found an interesting (that's interesting in the 'I just spent an hour debugging <em>that</em>?' sense) characteristic in SAS. If you have a variable, <code>x</code>, and are using the <code>lag</code> of <code>x</code>, do NOT put the <code>lag(x)</code> inside a conditional statement. This can apparently cause some pretty strange results. It is probably easier to see through code than to explain:</p>

<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-6">
<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> test;</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> id$<span style="color: #2e8b57; font-weight: bold;color:#800000;">1</span> <span style="color: #0000ff;">x</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;">cards;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; a <span style="color: #2e8b57; font-weight: bold;color:#800000;">1</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; a <span style="color: #2e8b57; font-weight: bold;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; a <span style="color: #2e8b57; font-weight: bold;color:#800000;">3</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; b <span style="color: #2e8b57; font-weight: bold;color:#800000;">12</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; b <span style="color: #2e8b57; font-weight: bold;color:#800000;">13</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; b <span style="color: #2e8b57; font-weight: bold;color:#800000;">15</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>
<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;</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> test;</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> test;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; lagid=<span style="color: #0000ff;">lag</span><span style="color: #66cc66;">&#40;</span>id<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: #0000ff;">if</span> lagid=id <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; lagx=<span style="color: #0000ff;">lag</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">x</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; &nbsp; duration=x-lagx;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <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;">&nbsp;</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;">proc print</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>And here are the results:</p>

<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-7">
<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;">Obs&nbsp; &nbsp; id&nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">x</span>&nbsp; &nbsp; lagid&nbsp; &nbsp; lagx&nbsp; &nbsp; duration</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #2e8b57; font-weight: bold;color:#800000;">1</span>&nbsp; &nbsp; &nbsp;a&nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">1</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.</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: #2e8b57; font-weight: bold;color:#800000;">2</span>&nbsp; &nbsp; &nbsp;a&nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">2</span>&nbsp; &nbsp; &nbsp; a&nbsp; &nbsp; &nbsp; &nbsp; .&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #2e8b57; font-weight: bold;color:#800000;">3</span>&nbsp; &nbsp; &nbsp;a&nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">3</span>&nbsp; &nbsp; &nbsp; a&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">2</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">1</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: #2e8b57; font-weight: bold;color:#800000;">4</span>&nbsp; &nbsp; &nbsp;b&nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">12</span>&nbsp; &nbsp; &nbsp; a&nbsp; &nbsp; &nbsp; &nbsp; .&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #2e8b57; font-weight: bold;color:#800000;">5</span>&nbsp; &nbsp; &nbsp;b&nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">13</span>&nbsp; &nbsp; &nbsp; b&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">3</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2e8b57; font-weight: bold;color:#800000;">10</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: #2e8b57; font-weight: bold;color:#800000;">6</span>&nbsp; &nbsp; &nbsp;b&nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">15</span>&nbsp; &nbsp; &nbsp; b&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">13</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #2e8b57; font-weight: bold;color:#800000;">2</span> </div></li></ol></div>
</div></div><br />

<p>There are obviously some strange things going on here. I have no idea what is going on in the 2nd row of the results where <code>lagx</code> is missing when it should be 1. And in the 5th row, <code>lagx</code> is the 3 from 2 rows above when it should be 12. Luckily, the solution is easy. Just execute the lag every time:</p>

<div class="syntax_hilite"><span class="langName">SAS:</span><br /><div id="sas-8">
<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> test;</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> test;</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; lagid=<span style="color: #0000ff;">lag</span><span style="color: #66cc66;">&#40;</span>id<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; lagx=<span style="color: #0000ff;">lag</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">x</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: #0000ff;">if</span> lagid=id <span style="color: #0000ff;">then</span> <span style="color: #0000ff;">do</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; duration=x-lagx;</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: #0000ff;">end</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>Anyway, it took me two years to run into this so I guess this isn't a common mistake but if you're ever having trouble with a <code>lag</code>, check to make sure it is executed for every line of the data.</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

