The MCHP SAS MANUAL - Data Preparation Examples

         

Home    Contents

GENERAL GUIDELINES:
Windows in SAS
File management

The SAS Program
Program syntax
Debugging tips


 USING SAS PROGRAMMING TO: 
   
1. Prepare the data set 
   Types of data 
   Example programs    
    
2. View the data
   SAS Procedures
  
3. Explore the data  
   Numeric statistics    
   Frequency tables    
    
4. Manipulate the data  
   Basic techniques    
   New variables
  
5. Adding Variables and 
Observations to Data Sets
   The SET Statement
   The MERGE Statement

6. Data Processing
   ARRAY Statement
   Do Loops
   By-Group Processing
   RETAIN Statement
  
NON-PROGRAMMING 
      Alternatives

 
SAMPLE DATA SETS: 
 Height/weight
 Height/weight/region
 Simulated clinical data 
 Simulated Manitoba Health 
    

I. DATA PREPARATION: PROGRAM EXAMPLES


Several examples are shown here of creating and reading/accessing data sets for: 1) Permanent SAS data sets, 2) Temporary SAS data sets, and 3) Raw data sets.

1) Permanent SAS Data Sets

*************************************************
*This program CREATES a permanent SAS data set  *
*it assumes that a temporary SAS data set has   *
*already been created during the SAS session.   *
*************************************************;

libname sasref 'c:\sasdir';
    /* where to store the new permanent SAS data set*/

data sasref.new;   
       /* create a permanent SAS data set in the 
          sasdir directory */
       
  set htwt;     
       /* access, or read, a temporary SAS data set*/
       
run;
***************************************************
*This program READS a permanent SAS data set,     *
*creating a temporary SAS data set.               *
***************************************************;

libname sasref 'c:\sasdir';  
    /* location of permanent SAS data set on C: drive */

data one;  
     /* create a temporary SAS data set */

  set sasref.survey; 
     /* read the permanent SAS data set called "survey" */
run;

**************************************************
*The above program also CREATES a temporary SAS  *
*data set from a permanent SAS data set.         *
**************************************************;

 

2) Temporary SAS data sets

*************************************************
*This program READS a temporary SAS data set,   *
*creating another temporary SAS data set.       *
*It assumes that "one" has already been created *
*during the SAS session.                        *
*************************************************;

data two;
     /* create a temporary SAS data set called "two" */

  set one; 
     /* read the data set called "one" */

if gender='F'; 
     /* keep only females in the "two" data set */
        /* (this assumes the variable "gender" 
           exists in "one")*/
run;

3) Raw data sets


******************************************************
*This program CREATES a permanent SAS data set       *
*from a file containing raw data. (To create a       *
*temporary SAS data set, a libname is not needed.    *
*The libname would come out and the data statement*
*would be data one instead of data sasref.one).      *
*****************************************************;

filename rawref 'c:\sasdir\rawdata'; 
  /* name and location of raw data file on C: drive */

libname sasref 'c:\sasdir'; 
/* location for new permanent SAS data set */

data sasref.one;    
  /* create a permanent SAS data at the sasref location*/
  infile rawref;
  input name $1-10
        sex $12
        sales 20-25;
run;

Home
Ia. Data Preparation: Types of Data
NEXT
II. View the data

Contact: Charles Burchill       Telephone: (204) 789-3429
Manitoba Centre for Health Policy
Department of Community Health Sciences, University of Manitoba
4th floor Brodie Centre
408 - 727 McDermot Avenue
Winnipeg, Manitoba R3E 3P5       Fax: (204) 789-3910
Last modified on Monday, 12-Sep-2005 12:43:51 CDT