I am using a basic select statement to pull some accounts. I need to output those accounts in a single cell, and not rows of accounts.
Asked
Active
Viewed 77 times
-2
-
How do you want it? Comma separated? – Atk Feb 04 '20 at 07:43
-
comma is fine, yes – Eyal Marom Feb 04 '20 at 07:44
-
Are you using sql-server? – Atk Feb 04 '20 at 07:46
-
no. sql via SAS – Eyal Marom Feb 04 '20 at 07:47
-
SELECT STUFF( (SELECT ',' + CONVERT(varchar,accounts) FROM #YourTable FOR XML PATH ('')), 1, 1, '' ) as output – Atk Feb 04 '20 at 07:49
-
check if it works. – Atk Feb 04 '20 at 07:50
-
https://stackoverflow.com/questions/194852/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-serv – cosmos Feb 04 '20 at 07:56
-
doesn't work; getting an error. I must stress that I am using SQL syntax via SAS, while connecting to database in TERADATA. – Eyal Marom Feb 04 '20 at 08:08
-
Update the question to show your basic select statement and any error messages that are appearing in the SAS log. Are you using the DMS (desktop SAS), Enterprise Guide or SAS Studio client ? – Richard Feb 04 '20 at 17:21
1 Answers
0
PROC SQL;
CREATE TABLE WORK.WANT AS
SELECT /* Concatenated */
(cats(t1.COLUMN_1, ', ', t1.COLUMN_2)) AS ConcatenatedColumns
FROM WORK.HAVE t1;
QUIT;
I guess you need to have concatenated results from some table?
cats() function can be used to concat values of different columns, with removed leading and trailing blanks.

Niqua
- 386
- 2
- 15