ASReml · Simulations Using SAS

This page was last modified on 01 November 2007, at 15:55 NZST

I have been working with a friend of mine in a breeding strategy simulation project using SAS (!!). I would rather use S+ or R for this type of simulation, but the only computer languages that we have in common with my friend were SAS and Fortran. The latter was just too much work compared to using a matrix language like Matlab, Python+Numpy, R or… SAS IML.

Programming data generation in SAS IML was not that difficult, but then we needed to:

  1. Save data,
  2. Run ASReml from inside SAS,
  3. Read the variance components from the .asr file and store them for further processing.

Running ASReml from SAS can be done using the call system function call, but rather than calling ASReml directly, one calls a .bat file, allowing for more complex commands. Let’s say that analysis.bat contains the following commands:

⚠ (:source:)[@ asreml -ls5 dotasr.as exit @]

The first line calls ASReml, while the second one closes the DOS (or command) window. Then the .bat file can be called using something like:

⚠ (:source lang=SAS:)[@ data _null_; call system('c:\simproj\analysis.bat'); run; @]

SAS is very good at reading files with a clear format (like comma or space-separated values, as in the .sln or .yht files) but not that great at reading free-form files (like .asr files). I wrote this little bit of SAS code to read the .asr file, which is working fine — at least for the simple univariate analyses I have tested.

⚠ (:source lang=SAS:)[@ filename dotasr 'c:\simproj\optest.asr'; <:vspace> data asreml comps(keep = component value stderr); infile dotasr dlm="%" missover; length string $ 100; input string; * String with the name of variance components to read; comps = 'Variance Block treeID'; id = scan(string, 1, " "); pos = index(comps, strip(id)); if index(comps, strip(id)) > 0 then do; component = id; value = scan(string, 5," "); stderr = scan(string, 6," "); output comps; end; run; @]

I have also some instructions for running simulations using Python.

Keywords: SAS.