Wednesday, December 21, 2011

SAS: Merging Log and Output in a single file

SAS typically displays the code, log and procedure output in separate windows.  You can use PROC PRINTTO to re-direct log and procedure output into a single file. Since the code run is typically mirrored in the log file, you have a nice single file documenting your code and output, along with any warnings and other useful information from the log file.  The trick is to specify the same file in the log= and print= options in PROC PRINTTO

For example:

proc printto log="I:\sasods\printto_test.txt" print="I:\sasods\printto_test.txt";
data numbers;
   input x y z;
 14.2   25.2   96.8
 10.8   51.6   96.8
  9.5   34.2  138.2
  8.8   27.6   83.2
 11.5   49.4  287.0
  6.3   42.0  170.7
proc print data=numbers;
   title 'Listing of NUMBERS Data Set';

proc printto;

creates the following file:

NOTE: PROCEDURE PRINTTO used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

3    data numbers;
4       input x y z;
5       datalines;

NOTE: The data set WORK.NUMBERS has 6 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

12   ;
14   proc print data=numbers;
15      title 'Listing of NUMBERS Data Set';
16   run;

Listing of NUMBERS Data Set

Obs      x       y       z

 1     14.2    25.2     96.8
 2     10.8    51.6     96.8
 3      9.5    34.2    138.2
 4      8.8    27.6     83.2
 5     11.5    49.4    287.0
 6      6.3    42.0    170.7
NOTE: There were 6 observations read from the data set WORK.NUMBERS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

18   proc printto;
19   run;

 The last PROC PRINTTO resets to the default output and log destinations.

Wednesday, December 14, 2011

Running Stata in batch from SAS

Admit it - some statistical software packages have an easier way of doing something than others. That's why one may want to use two or more packages on the same data.  Here is an easy way to run Stata code from SAS.

1.  Output the data set from SAS using PROC EXPORT.
proc export data=out

2.  Make a Stata .do file that would read in data1.csv and perform the desired analysis.  Save it as 'C:\Clients\StataFromSAS\".  For example:
insheet using 'C:\Clients\StataFromSas\data1.csv', clear
set linesize 100
summarize var1
tab var1

3.  In SAS, the X statement issues an operating-environment command from within a SAS session (e.g. performs a DOS command under Windows).  Since Stata can be run from a DOS prompt in batch mode, we can call its .do file from SAS using X statement.  First, change DOS directory to where the Stata log file should go, and then execute in batch mode (for more on Stata in batch mode, see appendix C.5 of Stata [GS] manual).  The following SAS statements accomplish this:
x "cd C:\Clients\StataFromSAS\";
x '"C:\Program Files (x86)\Stata12\StataSE-64.exe" /e do "C:\Clients\StataFromSAS\"';

4. Enjoy :)

Tuesday, December 13, 2011

Spam & HIV share behaviors?

A perhaps interesting curiosity:

Statistical Computing Platform for Python

I came over this talk proposal for the 2012 Python Conference:


pandas is a Python library providing fast, expressive data structures for working with structured or relational data sets. In addition to being used for general purpose data manipulation and data analysis, it has also been designed to enable Python to become a competitive statistical computing platform.
In contrast to other tools in domain-specific data analysis languages like R, it features deeply integrated array axis indexing which enables intuitive data alignment, pivoting and reshaping, joining and merging, and other kinds of standard relational data manipulations. 
 While I've not looked at nor used the library at this point, if anyone would like to explore or try it out for their work, please let me know - I'd be happy to dive into it with you.

- Yarko

Sunday, December 11, 2011

Subscribe via email

Enter your email address:

Delivered by FeedBurner


google analytics