Posts Tagged ‘ Statistical Programming ’

A surprising result: The expected number of uniform variates whose sum exceeds one

September 26, 2012
By
A surprising result: The expected number of uniform variates whose sum exceeds one

I was recently flipping through Ross' Simulation (2006, 4th Edition) and saw the following exercise: Let N be the minimum number of draws from a uniform distribution that exceed 1. What is the expected value of N? Write a simulation to estimate the expected value. For example, if v =
Read more »

Tags: , ,
Posted in SAS | Comments Off

Grouping observations based on quantiles

September 24, 2012
By
Grouping observations based on quantiles

Sometimes it is useful to group observations based on the values of some variable. Common schemes for grouping include binning and using quantiles. In the binning approach, a variable is divided into k equal intervals, called bins, and each observation is assigned to a bin. In this scheme, the size
Read more »

Tags: , ,
Posted in SAS | Comments Off

Filling the lower and upper triangular portions of a matrix

September 17, 2012
By
Filling the lower and upper triangular portions of a matrix

If you use a word three times, it's yours. -Unknown When I was a child, my mother used to encourage me to increase my vocabulary by saying, "If you use a word three times, it's yours for life." I believe that the same saying holds for programming techniques: Use a
Read more »

Tags: , ,
Posted in SAS | Comments Off

Testing for equality of sets

September 6, 2012
By
Testing for equality of sets

Ah! The joys of sets! It is easy to test whether two vectors are equal in SAS/IML software. It is only slightly more challenging to test whether two sets are equal. Recall that A and B are equal as sets if they contain the same elements. Order does not matter.
Read more »

Tags: ,
Posted in SAS | Comments Off

How to return multiple values from a SAS/IML function

August 20, 2012
By

The SAS/IML language supports user-defined functions (also called modules). Many SAS/IML programmers know that you can use the RETURN function to return a value from a user-defined function. For example, the following function returns the sum of each column of matrix: proc iml; start ColSum(M); return( M ); /*
Read more »

Tags: , ,
Posted in SAS | Comments Off

Extract the lower triangular elements of a matrix

August 16, 2012
By
Extract the lower triangular elements of a matrix

It is common to want to extract the lower or upper triangular elements of a matrix. For example, if you have a correlation matrix, the lower triangular elements are the nontrivial correlations between variables in your data. As I've written before, you can use the VECH function to extract the
Read more »

Tags: , , ,
Posted in SAS | Comments Off

Visualize the bivariate normal cumulative distribution

July 11, 2012
By
Visualize the bivariate normal cumulative distribution

When you are working with probability distributions (normal, Poisson, exponential, and so forth), there are four essential functions that a statistical programmer needs. As I've written before, for common univariate distributions, SAS provides the following functions: the PDF function, which returns the probability density at a given point the CDF
Read more »

Tags: , , ,
Posted in SAS | Comments Off

Reordering data to match a target order

July 9, 2012
By
Reordering data to match a target order

Suppose that you have two data vectors, x and y, with the same number of elements. How can you rearrange the values of y so that they have the same relative order as the values of x? In other words, find a permutation, π, of the elements of y so
Read more »

Tags: , ,
Posted in SAS | Comments Off

Welcome!

SAS-X.com offers news and tutorials about the various SAS® software packages, contributed by bloggers. You are welcome to subscribe to e-mail updates, or add your SAS-blog to the site.

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.