Translating One Set of Character Values to Another - SAS Programming

The TRANSLATE function does just what the name implies—it translates one character to another.The function takes the form:

new_char_var=TRANSLATE (char_var,to_string,from_string);

The to_string and from_string can be one or more characters in length; each byte of the to_string is substituted for the corresponding byte in the from_string. Suppose you have an optical mark reading machine which scans multiple choice exams.Each question has five possible answers, 'A' through 'E', but the machine can only produce a file of answers containing the numerals '1' through '5'.In order to take the file produced by the machine and translate the numerals '1' through '5' to the letters 'A' through 'E' respectively, you code the following:

Example

DATA TRANS;
ARRAY QUES[1Q] $ 1 QUES1-QUES10;
INPUT (QUES1-Q.UES10)($1.)J
DO J * 1 TO 10;
QUES[J]=TRANSLATE (QUES[J],'ABODE','12345');
END;
DROP J;
DATALINES;
2412552134
1234512345
RUN;

The resulting values for QUES1-QUES10 for the observation 1 are: B, D, A, B, E, E, B, A, C, D. Please refer to Chapter 7 for a discussion on using ARRAYS


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics