DATA Step, Macro, Functions and more

Is it possible to concatenate two values inside Proc SQL?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 210
Accepted Solution

Is it possible to concatenate two values inside Proc SQL?

[ Edited ]

I have the following Proc SQL:

proc sql;
	create table dm1 as
	select STUDYID, DOMAIN, dm.SubjectID, USUBJID 
	from train.dm,train.cp
	where dm.subjectid=cp.subjectid 
	order by subjectid
;
quit;

 USUBJID should be the a concatination of SubjectID and  STUDYIDUSUBJID = STUDYID || SubjectID . How can it be actualized inside the Proc SQL? Thank you!


Accepted Solutions
Solution
‎09-08-2017 05:19 PM
PROC Star
Posts: 1,308

Re: Is it possible to concatenate two values inside Proc SQL?

Posted in reply to DmytroYermak

 

 

proc sql;
	create table dm1 as
	select STUDYID, DOMAIN, dm.SubjectID, SubjectID||STUDYID as USUBJID 
	from train.dm,train.cp
	where dm.subjectid=cp.subjectid 
	order by subjectid
;
quit; 

View solution in original post


All Replies
Solution
‎09-08-2017 05:19 PM
PROC Star
Posts: 1,308

Re: Is it possible to concatenate two values inside Proc SQL?

Posted in reply to DmytroYermak

 

 

proc sql;
	create table dm1 as
	select STUDYID, DOMAIN, dm.SubjectID, SubjectID||STUDYID as USUBJID 
	from train.dm,train.cp
	where dm.subjectid=cp.subjectid 
	order by subjectid
;
quit; 
Regular Contributor
Posts: 210

Re: Is it possible to concatenate two values inside Proc SQL?

Posted in reply to novinosrin
Thank you, novinosrin. I asked but even not having checked on my own).
Super User
Posts: 13,023

Re: Is it possible to concatenate two values inside Proc SQL?

Posted in reply to DmytroYermak

If any of your your SubjectID are shorter than the defined length of the variable you may get unwanted spaces in the middle of the USUBJID variable:

data junk;
   length subjectid $ 10;
   subjectid = 'abc';
   studyid = '123';
run;

proc sql;
   select studyid, subjectid,SubjectID||STUDYID as USUBJID 
   from junk;
run; 

If you don't want the space in the middle then use Cats(SubjectId,StudyId) as Usubjid

 

Super User
Posts: 22,843

Re: Is it possible to concatenate two values inside Proc SQL?

Posted in reply to DmytroYermak

CATS/CATT functions can be used similarly to any other function within PROC SQL.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 154 views
  • 3 likes
  • 4 in conversation