The MCHP SAS MANUAL - Create Height/Weight/Region - program

         


Sample Data Sets: Height/Weight/Region - Program

This program can be used to create a temporary SAS data set called "htwt_reg" from scratch. Nothing else is needed to produce this data set. This data set will be available at any time during the SAS session. For subsequent sessions, the saved program can be run again to re-create the "htwt_reg" data set.
  1. Enter the following program directly into the SAS Program Editor window (the comments do not need to be entered).
  2. Save the program (e.g., htwtregprog.sas).
  3. Submit the program for processing.
  4. Check both log and output windows to ensure the program ran accurately
  5. Debug the program, if necessary; save it again, and submit it again (clearing the log and output windows first so that only the most recently-submitted versions will appear).
It is important to line up the values for the 18 observations exactly as specified in the INPUT statement. The INPUT statement indicates that values for NAME, for example, can take up to 10 spaces, beginning at column 1, and that the values should be read in as character ($). There are 3 spaces, from column 11-13, and then REGION (also read in as character and can take up 12 spaces) is entered at column 14 (or the 14th space over from the beginning of the line). It must be entered at this 14th space if SAS is to pick up the values of REGION for each observation. The values for each observation should thus be lined up, in columns, as specified in the INPUT statement (the space bar can be used to count over to the appropriate column, or space, on the screen).
****************************************** 
* Example 3 - only for creating *
* htwt_reg data used *
* f=htwt_reg_cr.sas *
* *
* This program creates a temporary *
* SAS data set used in in the example 3 *
* program. In most cases this data set *
* will be available as a permanent SAS *
* file in the course library *
****************************************** ;
data htwt_reg                ; 
               ** informats are similar to usign an informat on 
               an input statement to define the lenght of 
               a variable. This method is often used 
               when reading variable length fields from 
               list or delimited input files. ; 
informat name $10. region $12. ; 
input @1 name @14 region ; 
cards ; 
Aubrey       Winnipeg 
Ron          Winnipeg 
Carl         Winnipeg 
Antonio      Winnipeg 
Deborah      Non-Winnipeg 
Jacqueline   Winnipeg 
Helen        Winnipeg 
David        Winnipeg 
James        Non-Winnipeg 
Michael      Winnipeg 
Ruth         Non-Winnipeg 
Joel         Non-Winnipeg 
Donna        Winnipeg 
Roger        Winnipeg 
Yao          Winnipeg 
Elizabeth    Winnipeg 
Tim          Non-Winnipeg 
Susan        Non-Winnipeg 
; 
run; 
proc contents data=htwt_reg;       /* Begin a PROC step */
run;                               /* End the PROC step */
    /* View the values of the 1st 10 observations */
proc print data=htwt_reg(obs=10);  /* Begin a PROC step */
run;                               /* End the PROC step */

Last modified on