I've got a query that creates a new output table field by concatenating a variable to an input table field as follows:
"&threespaces" || EMPLOYEE.PERSON_UID,9) as NEWKEY
However, when I run my query, it complains because the EMPLOYEE_PERSON_UID is numeric. How might I convert this field so the query doesn't complain? I am aware that SAS usually ignores spaces or blanks at the beginning of a field, however, this field needs the "threespaces" at its beginning.
SAS is really picky about the difference between character and numeric variables -- and spaces are not valid in a number. I assume that you want the NEWKEY variable to be character. The key is doing your concatenate with a PUT function to turn the ID variable into a character value for the concatenate operation. Then the format=$char12. will tell SAS to respect the leading blanks in the new field--which will be a CHARACTER variable.
input name $ PERSON_UID;
proc print data=employee;
title 'person_uid is numeric';
create table testit as
select name, employee.person_uid,
' '||left(put(employee.person_uid,9.)) as NEWKEY format=$char12.
from work.employee as employee;
proc print data=testit;
title 'NEWKEY is a character variable';
title2 'So the PUT function was used to turn a numeric var into a character value for the concat.';