As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Tip of the Day

From sasCommunity
Revision as of 13:42, 19 May 2017 by Paulkaefer (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

sasCommunity Tip of the Day

You can use the POINT option of the SET statement to efficiently select a random sample of observations from a SAS data set. In addition to any statistical reasons for drawing a random sample, the technique is also useful to create test data from a large file. The program shown here efficiently samples a large data set.

It reads only the observations that have been selected using the POINT option.

  • You assign a variable that is the desired sample size. The example here selects a 10% sample. You can also assign a fixed value (e.g., 100).
  • The DO loop is iterated for each observation
  • The uniform function is compared to the percent of observations still to be selected
  • If the observation is selected, it is read and output and the number needed is decremented by 1
  • Regardless the number of observations left is reduced by 1
  • The STOP statement is very important as without it, the DATA step will enter an infinite loop.

This technique works by modifying the threshold as observations are read and selected. Every observation has the same probability of being selected so the technique is statistically valid (If you are a statistician, you probably know this. If not, the analogy of drawing straws is the logic behind this.).

data subset;
 SampleSize = round(.1*numberObs,1);
 Left = numberObs;
 do i = 1 to numberObs;
    set point = i nobs = numberObs;
    if uniform(0) le SampleSize/Left then
    do;  /* select the observations */
       SampleSize + (-1); /* decrement needed by 1 */
    end; /* select the observations */
    Left +(-1); /* decrement remaining obs by 1 */
Submitted By Don Henderson

Feel free to comment on this tip.

Prior tip - Next tip -- Random Tip

Submit a Tip


Tips Index by Status

Currently in Use | Yet to be Scheduled | Still Under Review | Tip Awaiting Refinement

Search Tips:

The Tip of the Day Project

A new technical Tip of the Day related to SAS software will be shown on this page and the main page every day. Before getting started, you can Browse and Search the current list of tips contributed by users.

Anyone can participate. We hope you do! Here's how:

  1. Submit a Tip by posting a SAS tip that you think others might find useful
  2. Review a Tip prior to publishing
This effort is similar to, and was motivated by, the Wikipedia Tip of the Day Project. Please tell us what you think