Published on :
ETL CREATION_INTERNE

Time Unit Conversion using Arrays and Loops

This code is also available in: Deutsch Español Français
Awaiting validation
This program illustrates the use of SAS© arrays (ARRAY) to apply an identical mathematical transformation to multiple columns. It creates a test dataset, converts values (division by 60 with rounding to 0.1) via a DO loop, and displays the final result.
Data Analysis

Type : CREATION_INTERNE


Data is generated directly in the code via the DATALINES statement within the DATA EXPER step.

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'EXPER' dataset containing 5 numerical variables (TIME0 to TIME4) populated by internal data (datalines).
Copied!
1DATA EXPER;
2 INPUT TIME0-TIME4;
3DATALINES;
4100 200 300 400 500
555 110 130 150 170
6;
2 Code Block
DATA STEP Data
Explanation :
Data transformation in the 'MINUTES' table. Uses an ARRAY to reference the TIME0-TIME4 columns and a DO loop to divide each value by 60 and round it to the first decimal place.
Copied!
1DATA MINUTES;
2 SET EXPER;
3 array TIME[0:4] TIME0-TIME4;
4 DO i = 0 to 4;
5 TIME[i]= round(TIME[i]/60,0.1);
6 END;
7 drop i;
3 Code Block
PROC PRINT
Explanation :
Printing of the transformed 'MINUTES' dataset to standard output.
Copied!
1 
2PROC PRINT
3DATA=MINUTES;
4title'Problem 15.8 Listing of Time Measured in Minutes';
5RUN;
6 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.