My apologies. I assumed that adding the BYTE function to the code was a workaround when a file with the actual character was opened into SAS Studio. If the encoding of your SAS session is WLATIN1, I agree that the code you have should work. However, since you are seeing the errors about invalid characters present in the data, there is a possibility that the encoding of your SAS session is UTF-8. Run this to verify.
PROC OPTIONS OPTION=ENCODING; RUN:
The ASCII characters (7-bit) are represented as one byte in UTF-8. All other characters, including the ±, must be represented as more than one byte. Since the BYTE function only returns one byte, the value for 177 is invalid in UTF-8. That could cause the errors you see.
The UTF-8 hexadecimal representation for ± is C2B1. If your SAS session encoding is UTF-8, you can use the following statement to add that character to the string directly:
c = trim(left(put(a,10.2))) || 'c2b1'x || trim(left(put(b,10.2)));
You could also use KPROPDATA to convert the result of BYTE to UTF-8. That's slightly more complicated but looks like this:
c = trim(left(put(a,10.2))) || KPROPDATA(BYTE(177), 'uesc', 'wlatin1', 'utf8') || trim(left(put(b,10.2)));
... View more