data Weight; 1 infile 'your-input-file'; 2 input IDnumber $ week1 week16; 3 WeightLoss=week1-week16; 4 run; 5 proc print data=Weight; 6 run; 7
| 1 | Begin the DATA step and create a SAS data set called WEIGHT. |
| 2 | Specify the external file that contains your data. |
| 3 | Read a record and assign values to three variables. |
| 4 | Calculate a value for variable WeightLoss. |
| 5 | Execute the DATA step. |
| 6 | Print data set WEIGHT using the PRINT procedure. |
| 7 | Execute the PRINT procedure. |
data Weight2; 1 input IDnumber $ week1 week16; 2 AverageLoss=week1-week16; 3 datalines; 4 2477 195 163 2431 220 198 2456 173 155 2412 135 116 ; 5 proc print data=Weight2; 6 run;
| 1 | Begin the DATA step and create SAS data set WEIGHT2. |
| 2 | Read a data line and assign values to three variables. |
| 3 | Calculate a value for variable WeightLoss2. |
| 4 | Begin the data lines. |
| 5 | Signal end of data lines with a semicolon and execute the DATA step. |
| 6 | Print data set WEIGHT2 using the PRINT procedure. |
| 7 | Execute the PRINT procedure. |
data weight2; infile datalines missover; 1 input IDnumber $ Week1 Week16; WeightLoss2=Week1-Week16; datalines; 2 2477 195 163 2431 2456 173 155 2412 135 116 ; 3 proc print data=weight2; 4 run; 5
| 1 | Use the MISSOVER option to assign missing values to variables that do not contain values in records that do not satisfy the current INPUT statement. |
| 2 | Begin data lines. |
| 3 | Signal end of data lines and execute the DATA step. |
| 4 | Print data set WEIGHT2 using the PRINT procedure. |
| 5 | Execute the PRINT procedure. |
data all_errors;
length filelocation $ 60;
input filelocation; /* reads instream data */
infile daily filevar=filelocation
filename=daily end=done;
do while (not done);
input Station $ Shift $ Employee $ NumberOfFlaws;
output;
end;
put 'Finished reading ' daily=;
datalines;
pathmyfile_A
pathmyfile_B
pathmyfile_C
;
proc sort data=all_errors out=sorted_errors;
by Station;
run;
proc print data = sorted_errors;
title 'Flaws Report sorted by Station';
run;data investment; 1 begin='01JAN1990'd; end='31DEC2009'd; do year=year(begin) to year(end); 2 Capital+2000 + .07*(Capital+2000); output; 3 end; put 'The number of DATA step iterations is '_n_; 4 run; 5 proc print data=investment; 6 format Capital dollar12.2; 7 run; 8
| 1 | Begin the DATA step and create a SAS data set called INVESTMENT. |
| 2 | Calculate a value based on a $2,000 capital investment and 7% interest each year from 1990 to 2009. Calculate variable values for one observation per iteration of the DO loop. |
| 3 | Write each observation to data set INVESTMENT. |
| 4 | Write a note to the SAS log proving that the DATA step iterates only once. |
| 5 | Execute the DATA step. |
| 6 | To see your output, print the INVESTMENT data set with the PRINT procedure. |
| 7 | Use the FORMAT statement to write numeric values with dollar signs, commas, and decimal points. |
| 8 | Execute the PRINT procedure. |