Technology Tales

Adventures & experiences in contemporary technology

Transferring data between SAS and R

5th June 2008

A question regarding the ability to transfer of data between SAS and R set me off on a spot of investigation a while back and I have always planned to share the results of my labours. Once I managed to locate the required documentation, things became clearer with further inspection. Functions from the foreign package seem to offer the most from the data import and export point of view so they’re what I’ll be featuring in this posting.

I’ll start with importing and using the read.ssd function makes life so much easier for getting SAS data into R. I discovered that the foreign package may not be loaded by default but you can determine this easily by issuing the following command:

search()

If “package:foreign” isn’t in the list, then you need to issue the following function call:

library(foreign)

Of course, if the foreign package isn’t installed, none of this will work. It should live in the library sub-folder of the main R installation directory but if it isn’t there, then downloading the relevant binary package from CRAN is in order. Assuming that all is installed, then a command like the following will perform the needful:

read.ssd("c:/data","data1",sascmd="C:/Program Files/SAS Institute/SAS/V8/sas.exe")

This creates a temporary SAS program that converts the SAS data set into a transport file for reading by another R function that is called in the background, read.xport. Form my experience, it all seems to work fairly seamlessly.

To get data out of R and into SAS is a multi-stage process, even with the foreign package. There are other ways but using the write.foreign seems more useful than most and here’s an example function call:

write.foreign(data1,"C:/test.txt","C:/test.sas",package="SAS",dataname="data1",validvarname="V7")

No SAS data sets are created at this stage but a text file is generated along with a SAS program for converting it into a data set. Running the SAS program is a separate step that follows the creation of the two files. Even if it is less streamlined than read.ssd, write.foreign does make easier to transfer data into SAS than having to write a program from scratch to read in write.table output.

In summary, R can neither read or write SAS data sets by itself so you need SAS installed to really make things happen. SAS gets called by read.ssd and I feel that it would be better if was called by write.foreign also rather than a SAS program generated for execution later on. Even so, it is good to see some custom functionality being provided that makes life easier. There’s also the hmisc package but my experiences while working with that on S-Plus have been such that it compares less favourably with foreign on the reliability front. Saying that, things may have changed since I last tried it.

New year, new blog

17th January 2007

Hello and welcome.

This may be the first time that you encountered me in cyberspace but this is not my first foray into the blogosphere: that is HennessyBlog. So why the new blog then? The reason is that I like the idea of somewhere to mull over computer technology, both new and old. And HennessyBlog is already devoted to the enjoyment of the great outdoors matters else and I do not want to dilute that focus. While a technology fan, I also like going walking in the countryside and visiting interesting towns and cities, capturing any views encountered with my camera. From these photos, I have compiled my online photo gallery and HennessyBlog also features news of updates to this.

So there you have it: this is going to be my technology blog. I do build my own PC’s so references to computer hardware may appear from time to time. Even so, I am more of a software person and programming is a love of mine. Currently, we also are going through a period where there are a lot of new software releases: who cannot have heard of the forthcoming versions of Windows and Office? I have been taking a look at some of these. Like anyone interested in computer technology, the Internet is also a big interest of mine, not least because I have been dabbling in web development for most of the last 10 years. I deliberately say development because, although I can probably do passable website interfaces, I am more technically adept than artistically gifted. I did mention programming earlier: this pays my bills so it may feature at some point.

ForecastFox issue

17th January 2007

ForecastFox should be a useful utility, adding a weather toolbar to Mozilla Firefox as it does. However, it developed a penchant for hogging the CPU when I upgraded from Firefox 2.0 to Firefox 2.0.0.1. I’ll hold out for a new version to see if the problem has been sorted. You can find out more here.

Mouse trouble

18th January 2007

For my home computing purposes, I use a Logitech MX700 cordless mouse. I have used a variety of Logitech devices over the years and never had any real trouble with them. Today, though, the MX700 failed to move the pointer around the screen. The first thing that comes to mind is connectivity, particularly as I use a Belkin OmniCube two port KVM switch. A quick test with my now retired MouseMan+ (it’s great when old kit backs you up: you wonder why you replaced it in the first place) confirmed that everything was OK on that front. Then, the thought struck me that the rechargeable NiMH batteries might have given up the ghost and were no longer recharging. I tried an old pair of NiCd‘s and everything seemed to work in spite of their not being fully charged. I will continue to use the MouseMan+ until they are fully charged and I will acquire some new NiMH rechargeables and monitor how everything goes.

Technet Plus subscription

19th January 2007

I have a free subscription to Microsoft‘s Microsoft Learn but with the onset of Vista and the latest issue dangles a carrot in front of me: the idea of a Technet Plus subscription. Trouble is that it is £283 per annum in the UK, not cheap. Nevertheless, that does rather neatly compare to the price of Windows Vista and that comes as part of the package. I think that I’ll revisit the idea when upgrading time comes and that will be a while after the Vista launch date of 30/1/2007. Given the security changes in the latest Windows incarnation, I’ll wait to ensure that I will not be put out too much before making the jump.

PSU shorting: one adventure too far…

20th January 2007

This morning, I got up to find my main computer powered off after I left it on overnight for a spyware scan by Webroot Spy Sweeper. After satisfying myself that it was dead, I tried popping a new fuse in the plug. What I saw next was far from being a pretty sight: shorting in the PSU. The fact that it took out a new 5 A fuse was neither here nor there (they are 20p a piece at where I replenished my supply: they may be cheaper elsewhere but what’s 20p these days?); thoughts of fried PC hardware are far from pleasant, especially the vision of losing data and expensive software purchases because a hard drive got fried by a shorting PSU. A whole new bare bones system from the likes of Novatech were appearing very ominously in my horizon.

There was only one thing for it: try another PSU and see if everything works. So, it was off to a nearby branch of PC World for a replacement. I know that there were other options but I preferred to get this problem sorted out pronto to put my mind at ease, if at all possible. The old PSU got taken out and the new one plugged in as part of pre-installation testing. Thankfully, I saw the Windows start up screen and the omens were good; it later turned out that my data were safe too. Initial problems with keyboard and mouse recognition were resolved by a reboot, as was an IP address conflict that had resulted because my back up machine was on throughout all of this. All in all, things turned out well after a solid lesson in backing up data outside of the PC on which it resides. Maybe an online service such as Diino could be very useful.

I do seem to have an issue with PSU’s giving up the ghost; maybe its the fact that I run them overnight a lot. This incident caused to upgrade from 450 W Jeantech unit to a 500 W one. The PSU that I had before the 450 W unit was higher rated but it couldn’t cope with the power demands of the machine it was powering up. The result was that it cut out a lot on start up, an annoying habit that I tolerated for longer than I really should. I’ll keeping an eye on things as I go…

Camera tales

20th January 2007

Anyone who has ever been on HennessyBlog will know that I enjoy walking in the countryside and that I always have a camera with me when I do. Like many digital SLR owners, I am beginning to see the tell-tale spots in my photos that are caused by a dirty sensor. And it isn’t that I am continually changing lenses either: I rarely remove the Sigma 18-50 mm DC zoom lens that I use with the camera. Rather than trusting myself with the cleaning (I have had a go already without much success), I am giving serious consideration to letting the professionals take care of my Canon EOS 10D, my only digital camera. I have already been quoted something of the order of £35 by a Canon service centre not far from me and am seriously considering taking them up on the offer.

Of course, sending it away to them means that I will have to forego the ability to include photos with posts on HennessyBlog describing my walks in the kind of timescale to which I have become accustomed; of course, this is where digital really scores. I will still have a camera with me as film remains my mainstay, even in this digital age. The camera in question is another Canon, an EOS 30 that I acquired used from Ffordes Photographic. While taking a recent peek at their website, I have just spied a used EOS 1V going for £399, a song for what remains Canon’s top of the range film SLR. Yes, I am tempted but I must stay real. In fact, I did not pay full price for my EOS 10D. That was part of the run-out stock that 7dayshop.com were selling off at next to half of the EOS 10D’s original asking price in the wake of its being superseded by the EOS 20D (itself since replaced by the EOS 30D: digital is a fast-moving world).

Sending a camera away for attention is not new to me as I also acquired a used Minolta X-700 manual focus SLR, again obtained from Ffordes, and that needed a spot of maintenance after a year in my possession. There was a problem with the shutter that cost me £75 to get Minolta to fix. Now that Minolta as a camera maker is no more, I was wondering who would attend to it in the future. That question was answered by a recent look on the web: in the UK it is JP Service Solutions, a division of Johnson’s Phototopia. Konica Minolta retain this information on their website. Konica Minolta’s failure to capitalise effectively on the digital revolution in its early days, particularly in the SLR area where they gifted their competitors a massive head start, cost them their future in the photographic business and now Sony continues the mantle, a sad end to one of camera manufacturing’s great innovators.

Returning to my digital-less dilemma, I suppose that I could get another digital for backup duty; I have to admit that a DSLR is a bulky contraption to be carrying in airline luggage. The camera that has made it onto my wish list is Ricoh’s GR Digital, a highly regarded offering that follows in the great tradition of its film forbears, the GR 1 and GR 21. Given that my first 35 mm camera was a Ricoh, and I have it still, this would be a case of returning to my roots. Of course, having it on a wish list is very different from having it on the to-do list and finances will certainly dictate if the purchase is made, though a finance deal offered by Warehouse Express does make it more accessible. Maybe some day…

Ricoh GR Digital

Adding a new hard drive

21st January 2007

Adding a new hard drive

Adding a new hard driveHaving during the week obtained a new 320 GB hard drive, today I am adding it to my system after yesterdays scare with a PSU. As with any such item, you need to format and configure it to work with your operating system, be it Windows, Linux or whatever. Good old Partition Magic can help with this (I have version 7 from the Powerquest days) but Windows XP (Professional, anyway) does offer its own tool for the job: the Disk Management console. Unfortunately, it’s a bit hard to find. The easiest way to get to it is to type diskmgmt.msc into the Run command box. Otherwise, it is a matter of setting your Start Menu to show the Administrative Tools group (Taskbar and Start Menu properties> Start Menu tab > Customise > Advanced tab) and accessing through the computer Management console for which there is a shortcut in this group. Of course, you need to have administrator access to your PC in order to to do any of this.

Hard drive partitioning

22nd January 2007

Hard drive partitioningIt has to be said that hard drive partitioning isn’t something that most people do very often, if at all in these days of cheap storage and system virtualisation. I must admit to having several disks in my main machine and can vouch for the virtues of virtualisation: VMware allows me to run multiple operating systems on the same machine, a very useful asset so long as enough memory is available. We can expect to hear more about virtualisation with the likes of Intel and AMD looking at hypervisor solutions for this.

Partitioning does give you what appear to be multiple drives from just the one and that is very useful when you only have a single hard drive in your PC. This was very much the case in my early computing days when catastrophic Windows 9x crashes (some self-inflicted…) often resulted in the pain of a complete re-installation of everything that had been on there. The independence offered by partitions certainly offered me peace of mind back then but 100MB Iomega Zip disks were a very useful defence in depth.

Without partitioning, my curiosity regarding the world of Linux would not have been sated though an approach involving multiple hard drives certainly came into play later on. Having been a Sun Solaris user at university, Linux certainly aroused much interest in me and I have to say that it has come a long, long way since my first ventures into its world.

While the Windows tool FDISK could partition hard drives for you, it wasn’t non-destructive: you had be prepared to restore all of your files from a backup and do a complete software re-installation following its use. It was designed for setting things up at the outset and not changing them later and that thinking seems to have pervaded the design of the Disk Management console found in XP.

For more flexible and non-destructive partitioning, Powerquest’s Partition Magic became the tool of choice, though I did have a dalliance with a package called Partition It before taking the plunge. Partition Magic is now in the Symantec stable and not a lot seems to be heard of it. Version 7, the last from Powerquest before its takeover, has been my staple but 983 errors have been thrown by the application at times and one partitioning operation went awry, forcing me to depend on my backups. Version 8 still throws 983 errors so I started to look beyond Partition Magic altogether. In my search, I happened on version 10 of Acronis Disk Director Suite. It got a strong recommendation from reviewer Davey Winder in PC Pro magazine (backup software True Image 10 from the same company also got a thumbs up from a different PC Pro reviewer) which gave some reassurance and I have to say that I agree. An operation refused by Partition Magic was completed successfully and safely so I know where my vote goes.

Office 2007 on test…

23rd January 2007

With its imminent launch and having had a quick at one of its beta releases, I decided to give Office 2007 a longer look after it reached its final guise. This is courtesy of the demonstration version that can be downloaded from Microsoft’s website; I snagged Office Standard which contains Word, Excel, PowerPoint and Outlook. Very generously, the trial version that I am using gives me until the end of March to come to my final decision.

And what are my impressions? Outlook, the application from the suite that I most use, has changed dramatically since Outlook 2002, the version that I have been using. Unless you open up an email in full screen mode, the ribbon interface so prevalent in other members of the Office family doesn’t make much of an appearance here. The three-paned interface taken forward from Outlook 2003 is easy to get around. I especially like the ability to collapse/expand a list of emails from a particular sender: it really cuts down on clutter. The ZoneAlarm anti-spam plug-in on my system was accepted without any complaint as were all of my PST files. One thing that needed redoing was the IMAP connection to my FastMail webmail account but that was driven more by Outlook warning messages than by necessity from a user experience point of view. I have still to get my Hotmail account going but I lost that connection when still using Outlook 2002 and after I upgraded to IE7.

What do I make of the ribbon interface? As I have said above, Outlook is not pervaded by the new interface paradigm until you open up an email. Nevertheless, I have had a short encounter with Word 2007 and am convinced that the new interface works well. It didn’t take me long to find my way around at all. In fact, I think that they have made a great job of the new main menu triggered by the Office Button (as Microsoft call it) and got all sorts of things in there; the list includes Word options, expanded options for saving files (including the new docx file format, of course, but the doc format has not been discarded either) and a publishing capability that includes popular blogs (WordPress.com, for instance) together with document management servers. Additionally, the new zoom control on the bottom right-hand corner is much nicer than the old drop down menu. As regards the “ribbon”, this is an extension of the tabbed interfaces seen in other applications like Adobe HomeSite and Adobe Dreamweaver, the difference being that the tabs are only place where any function is found because there is no menu back up. There is an Add-ins tab that captures plug-ins to things like Adobe Distiller for PDF creation. Macromedia in its pre-Adobe days offered FlashPaper for doing the same thing and this seems to function without a hitch in Word 2007. Right-clicking on any word in your document not only gives you suggested corrections to misspellings but also synonyms (no more Shift-F7 for the thesaurus, though it is still there is you need it) and enhanced on-the-spot formatting options. A miniature formatting menu even appears beside the expected context menu; I must admit that I found that a little annoying at the beginning but I suppose that I will learn to get used to it.

My use of Outlook and Word will continue, the latter’s blogging feature is very nice, but I haven’t had reason to look at Excel or PowerPoint in detail thus far. From what I have seen, the ribbon interface pervades in those applications too. Even so, my impressions the latest Office are very favourable. The interface overhaul may be radical but it does work. Their changing the file formats is a more subtle change but it does mean that users of previous Office versions will need the converter tool in order for document sharing to continue. Office 97 was the last time when we had to cope with that and it didn’t seem to cause the world to grind to a halt.

Will I upgrade? I have to say that it is very likely given what is available in Office Home and Student edition. That version misses out on having Outlook but the prices mean that even buying Outlook standalone to compliment what it offers remains a sensible financial option. Taking a look at the retail prices on dabs.com confirms the point:

Office Home and Student Edition: £94.61

Office Standard Edition: £285.50

Office Standard Edition Upgrade: £175.96

Outlook 2007: £77.98

Having full version software for the price of an upgrade sounds good to me and it is likely to be the route that I take, if I replace the Office XP Standard Edition installation that has been my mainstay over the last few years. Having been on a Windows 95 > Windows 98 > Windows 98 SE > Windows ME upgrade treadmill and endured the hell raised when reinstallation becomes unavoidable, the full product approach to getting the latest software appeals to me over the upgrade pathway. In fact, I bought Windows XP Professional as the full product in order to start afresh after moving on from Windows 9x.

  • All the views that you find expressed on here in postings and articles are mine alone and not those of any organisation with which I have any association, through work or otherwise. As regards editorial policy, whatever appears here is entirely of my own choice and not that of any other person or organisation.

  • Please note that everything you find here is copyrighted material. The content may be available to read without charge and without advertising but it is not to be reproduced without attribution. As it happens, a number of the images are sourced from stock libraries like iStockPhoto so they certainly are not for abstraction.

  • With regards to any comments left on the site, I expect them to be civil in tone of voice and reserve the right to reject any that are either inappropriate or irrelevant. Comment review is subject to automated processing as well as manual inspection but whatever is said is the sole responsibility of the individual contributor.