921 ************************************************* 922 * file = assign.sas * 923 * The SAS program in this file creates new * 924 * variables using assignment statements - * 925 * several arithmetic operators and the * 926 * SAS SUBSTR function. The program assumes * 927 * that the data set "htwt" has been created. * 928 *************************************************; 929 930 options linesize=min; 931 932 *----------------------------------------* 933 * Create a new temporary SAS data set, * 934 * same name, to add new variables * 935 *----------------------------------------*; 936 937 data htwt; 938 set htwt; 939 940 *------------------------------------------------* 941 * 1. Create new variables that incorporate * 942 * calculations made on the existing variables * 943 *------------------------------------------------*; 944 945 ht2p = (height + 2); /* Add 2 to "height" */ 946 agem1 = (age - 1); /* Subtract 1 from "age" */ 947 htfeet = (height/12); /* Convert inches to feet */ 948 /* Use the ROUND function to 949 limit decimals to 1 */ 950 htround = round(htfeet,0.1); 951 wtounce = (weight*16); /* Convert pounds to ounces*/ 952 953 *------------------------------------------------* 954 * 2. Create new variables that truncate the * 955 * values of existing variables. * 956 *------------------------------------------------*; 957 /* Starting at first value, 958 display first 2 values*/ 959 name1 = substr(name,1,2); 960 961 /* Starting at first value, 962 display first 3 values*/ 963 name2 = substr(name,1,3); 964 965 /* Starting at second value, 966 display first 3 values */ 967 name3 = substr(name,2,3); 968 969 run; NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 946:16 NOTE: The data set WORK.HTWT has 18 observations and 20 variables. NOTE: DATA statement used: real time 0.28 seconds 970 971 proc freq data=htwt; 972 tables height * ht2p * htfeet * htround /list missing; 973 tables age * agem1 /list missing; 974 tables weight * wtounce /list missing; 975 tables name * name1 * name2 * name3 /list missing; 976 title1 'The height/weight data set'; 977 title2 'Check new variables against original variables'; 978 run; NOTE: PROCEDURE FREQ used: real time 0.70 seconds