SAS: Getting 2×2 contingency table variables in the right order with PROC FREQ

By default, SAS will format a 2×2 contingency table like this if you have 1=yes 0=no binary variables:

|           | outcome=0 | outcome=1 |
| exposed=0 |           |           |
| exposed=1 |           |           |

But we want it like this:

|           | outcome=1 | outcome=0 |
| exposed=1 |           |           |
| exposed=0 |           |           |

The following code demonstrates how to do this:

And here's the output from this code:

AppleScript: Save Clipboard to Text File

This AppleScript will open a "Save as" dialog, which lets you specify a folder and filename, using the folder of the front-most Finder window as the default folder. It will then save the (text) contents of your clipboard to that .txt file.

tell application "Finder"
	if (count of windows) > 0 then
		set theDefault to the POSIX path of ((folder of window 1) as alias)
		set theDefault to path to desktop
	end if
end tell

set resultFile to (choose file name with prompt "Save As File" default name "paste.txt" default location theDefault) as text
if resultFile does not end with ".txt" then set resultFile to resultFile & ".txt"
set resultFilePosix to quoted form of the POSIX path of resultFile
do shell script "pbpaste > " & resultFilePosix

AppleScript to directly open a specific note in Evernote

I keep a daily work log in Evernote, and I wanted a quicker way to open up this note. AppleScript to the rescue!

tell application id "com.evernote.evernote"
	set notebook1 to "Cabinet"
	set myNotes to find notes "intitle:Note title goes here"
	set myNote to item 1 of myNotes
	open note window with myNote
end tell

AppleScript to open a new Safari window directly to the compose page in FastMail

Sometimes I like to be able to write an email without seeing the new messages in my inbox. This AppleScript (triggered with LaunchBar of course) solves this problem. It opens a new Safari window directly to FastMail's compose page.

Because FastMail loads so quickly and Safari is generally pretty fast fast, this is essentially the same speed of LaunchBar's "Compose Email" action for

tell application "Safari"
	make new document with properties {URL:""}
end tell

AppleScript to find FastMail tabs in Safari

I'm using the FastMail web interface more and more recently, but I keep losing the tab I keep it open in.

I found this AppleScript that is supposed to search Safari tabs based on the contents of a URL, but it gave me an error. So I fixed it (and hard-coded "" as the string to search for in the URL). I saved it as a .app file in Script Editor and trigger it with LaunchBar.

Update 1here's a (low-res) transparent icon pulled from FastMail's website that you can use for the .app created by Script Editor.

Update 2 (January 16, 2015): I've updated the script to fix a few bugs (like the window with the FastMail tab not actually coming to the front), and to automatically open FastMail in a new window if there isn't a current table open.

Terminal command to convert WAV to MP3

From the Apple StackExchange (user nqw1), this Terminal command will take all the WAV files in a folder and turn them into MP3s:

find . -name '*.wav' -maxdepth 1 -exec /usr/local/bin/lame -V 0 -q 0 '{}' \;

Apparently this is the highest quality (V is the best variable bitrate and q is the quality). This is apparently a bit faster and is the recommended setting:

find . -name '*.wav' -maxdepth 1 -exec /usr/local/bin/lame -V 0 -q 2 '{}' \;

Bookmarklet to re-perform a Duck Duck Go search on Google

I use Duck Duck Go as my primary search engine, but I often need to repeat a search on Google – Duck Duck Go is good, but nowhere near as good as Google for some searches, unfortunately.

I created this bookmarklet to prepend "!g" to the search and re-submit the search form. This will automatically perform the same search on Google.

If you use Safari and place it near the beginning of your bookmarks bar like I did, you can use ⌘3 (in my case; it's the third bookmark from the left) to trigger the bookmarklet.

Here's the "URL" for the bookmark that contains the JavaScript to do this:


(To install, you'll have to manually make a new bookmark in your bookmarks bar with the URL as the code above.) Get URL for selected message with AppleScript and TextExpander

I often use message://<> URLs to reference a specific email in OmniFocus or Evernote: clicking one of these URLs will automatically open up the source message in

There's not a great way to get these very handy message URLs without AppleScript, so based on this SuperUser answer, I created a TextExpander snippet.

Now, when I type xmsg, TextExpander will insert the message URL for the selected message in into whatever application I'm working in.

Here's the TextExpander snippet, and here's the AppleScript:

tell application "Mail"
	set selectedMessages to selection
	set theMessage to item 1 of selectedMessages
	set messageid to message id of theMessage
	-- Make URL (must use URL-encoded values for "<" and ">")
	set urlText to "message://" & "%3c" & messageid & "%3e"
	return urlText
end tell