An alternate coding.
Do you think the following Data step code will work? The changes are underlined and line numbers are included for reference.
1 DATA MIXED; 2 INPUT @20 TYPE $1. @; 3 IF TYPE = 1 THEN 4 INPUT ID 1-3 5 AGE 4-5 6 WEIGHT 6-8; 7 ELSE IF TYPE = 2 THEN 8 INPUT ID 1-3 9 AGE 10-11 10 WEIGHT 15-17; 11 DATALINES;
It produces exactly the same Proc Print output. But, always read the log!
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 3:7 7:12 NOTE: The data set WORK.MIXED has 5 observations and 4 variables.
When line 2 is executed, TYPE is given a character value. In the first execution the value is '1'.
When the IF expression is evaluated, the character value of TYPE does not match the data type of the value of the constant to the right of the equals sign. SAS has trouble trying to ask, "does '1'= 1 ?" It warns you that this is troubling. Then, it does a character to numeric conversion of the value of TYPE. Now SAS asks, "does 1= 1 ?" This it can do.