Susan Slaughter

Archive for January, 2011|Monthly archive page

Greatest Hits of 2010

In Detritus, Everything, SAS, SAS Global Forum, SAS Papers on January 19, 2011 at 9:55 am

I should have posted this a couple weeks ago, but I’ve been hard at work writing papers for SAS Global Forum (more about that in future posts!).

These were the popular posts and pages on in 2010.

1) What can I use SAS for?

2) Top 10 Reasons to Use SAS Enterprise Guide

3) SAS Papers, Etc.

4) A SAS Horror Story

5) Highlights of SAS Global Forum

Best Wishes for a Peaceful and Prosperous New Year!

SAS Data Step Illustrated: Guest Blog by Jiangtang Hu

In Everything, Guest Blog, Little SAS Book Series, SAS on January 4, 2011 at 11:07 am

The following blog is reprinted by permission of the author Jiangtang Hu. Hu is a SAS programmer living in Beijing who writes blogs in both English and Chinese. (Full disclosure: Hu quoted The Little SAS Book, but I had never met him before he wrote this blog.)

SAS Data Step’s Built-in Loop: An Illustrated Example

Some newbie SAS programmers take SAS as their first programming language ever learned. Sometimes they are confused by the concept of “data step’s built-in loop” even after reading the well-written The Little SAS Book: A Primer:

DATA steps also have an underlying structure, an implicit, built-in loop. You don’t tell SAS to execute this loop: SAS does it automatically. Memorize this:

DATA steps execute line by line and observation by observation.

Programmers could memorize the statement above and apply it well in their programming practices, but still find it hard to get the vivid idea about the so called implicit built-in loop. This post would make it easy.

The following will show an explicit loop example in C++. Note that you do not need to know anything about C++ to get the idea. Suppose that a data file data.dat in D drive holds three numbers


The question is how to (read and) print out these numbers and their sums. Following is the C++ approach (just read the bold section):

#include <iostream>
#include <fstream>
using namespace std;
int main()

int x;
int sum=0;
ifstream inFile;“d:data.dat”);
inFile >> x;

while (!inFile.eof( ))
sum = sum +x;
inFile >> x;

inFile.close( );
cout << “Sum = ” << sum << endl;
return 0;


There is an explicit loop in these C++ codes: while (!inFile.eof( )) . While it is not at the end of infile, the codes above will keep print out the numbers and do the accumulation. The final output is


The following SAS codes produce the exactly same output:

data _null_;

infile “d:\data.dat” end=eof;
input x;
put x;
if eof then put sum=;


Note that SAS codes do not need an explicit loop to reach to the end of file. There is a so called implicit built-in loop.