BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.

Thanks in advance!
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
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.
Good luck!
cynthia
[pre]
data employee;
infile datalines;
input name $ PERSON_UID;
return;
datalines;
alma 123456789
bob 234567890
carl 345678901
dave 456789012
;
run;

proc print data=employee;
title 'person_uid is numeric';
run;

proc sql;
create table testit as
select name, employee.person_uid,
' '||left(put(employee.person_uid,9.)) as NEWKEY format=$char12.
from work.employee as employee;
quit;

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.';
run;

[/pre]
deleted_user
Not applicable
Thanks, Cynthia,

Still being so darn new to all that SAS has to offer, I wasn't sure if the PUT code could be used inside a query. Your advice, as always, comes in handy!
deleted_user
Not applicable
Thanks for the information, Cynthia. I truly appreciate it.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2137 views
  • 0 likes
  • 2 in conversation