Reading Instream Data

Overview

Reading instream data is extremely helpful if you want to create data and test your programming statements on a few observations that you can specify according to your needs.
To read instream data lines that you enter directly in your SAS program, rather than data that is stored in an external file:
  • Insert a DATALINES statement as the last statement in the DATA step and immediately preceding the data lines.
  • Insert a null statement (a single semicolon) to indicate the end of the input data.
data sasuser.stress; 
   input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33 
         RecHR 35-37 TimeMin 39-40 TimeSec 42-43 
         Tolerance $ 45; 
   datalines;
2458 Murray, W      72 185 128 12 38 D
2462 Almers, C      68 171 133 10  5 I
2501 Bonaventure, T 78 177 139 11 13 I
2523 Johnson, R     69 162 114  9 42 S
2539 LaMance, K     75 168 141 11 46 D
2544 Jones, M       79 187 136 12 26 N
2555 King, E        70 167 122 13 13 I
2563 Pitts, D       71 159 116 10 22 S
2568 Eberhardt, S   72 182 122 16 49 N
2571 Nunnelly, A    65 181 141 15  2 I
2572 Oberon, M      74 177 138 12 11 D
2574 Peterson, V    80 164 137 14  9 D
2575 Quigley, M     74 152 113 11 26 I
2578 Cameron, L     75 158 108 14 27 I
2579 Underwood, K   72 165 127 13 19 S
2584 Takahashi, Y   76 163 135 16  7 D
2586 Derber, B      68 176 119 17 35 N
2588 Ivan, H        70 182 126 15 41 N
2589 Wilcox, E      78 189 138 14 57 I
2595 Warren, C      77 170 136 12 10 S
;
Syntax, DATALINES statement:
DATALINES;
Tip
  • You can use only one DATALINES statement in a DATA step. Use separate DATA steps to enter multiple sets of data.
  • You can also use LINES as the last statement in a DATA step and immediately preceding the data lines. Both LINES and CARDS are aliases for the DATALINES statement.
  • If your data contains semicolons, use the DATALINES4 statement plus a null statement that consists of four semicolons (;;;;).

Example: Reading Instream Data

To read the data for the treadmill stress tests as instream data, you can submit the following program:
data sasuser.stress;
   input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33 
         RecHR 35-37 TimeMin 39-40 TimeSec 42-43 
         Tolerance $ 45; 
   if tolerance='D'; 
   TotalTime=(timemin*60)+timesec; 
   datalines; 
2458 Murray, W            72  185 128 12 38 D 
2462 Almers, C            68  171 133 10  5 I 
2501 Bonaventure, T       78  177 139 11 13 I
2523 Johnson, R           69  162 114  9 42 S
2539 LaMance, K           75  168 141 11 46 D 
2544 Jones, M             79  187 136 12 26 N 
2552 Reberson, P          69  158 139 15 41 D 
2555 King, E              70  167 122 13 13 I 
2563 Pitts, D             71  159 116 10 22 S 
2568 Eberhardt, S         72  182 122 16 49 N 
2571 Nunnelly, A          65  181 141 15  2 I 
2572 Oberon, M            74  177 138 12 11 D 
2574 Peterson, V          80  164 137 14  9 D 
2575 Quigley, M           74  152 113 11 26 I 
2578 Cameron, L           75  158 108 14 27 I 
2579 Underwood, K         72  165 127 13 19 S 
2584 Takahashi, Y         76  163 135 16  7 D 
2586 Derber, B            68  176 119 17 35 N 
2588 Ivan, H              70  182 126 15 41 N 
2589 Wilcox, E            78  189 138 14 57 I 
2595 Warren, C            77  170 136 12 10 S 
;
Tip
Notice that you do not need a RUN statement following the null statement (the semicolon after the data lines). The DATALINES statement functions as a step boundary, so the DATA step is executed as soon as SAS encounters it.
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.71.106