DATA Step, Macro, Functions and more

Single column to multiple column of comma separated

Reply
New User
Posts: 1

Single column to multiple column of comma separated

Hey Experts,

 

I have a column data from my DB with a lot of values combined in a column. Each entry has multiple item ids separated by commas. I now need them in multiple columns. Any help will be appreciated.

 

Regards,

Contributor
Posts: 43

Re: Single column to multiple column of comma separated

You can google search for "sas csv import"
Also you can import file from sas "file - import csv file" section

PROC IMPORT DATAFILE="C:\test.csv"
OUT=SASCrunch
DBMS=csv
REPLACE;
GETNAMES=Yes;
RUN;
Super User
Posts: 9,681

Re: Single column to multiple column of comma separated

data have;
text='xx,ee,tt       ';output;
text='jj,ii,ii,kk';output;
run;
proc sql;
select max(countw(text,',')) into : max from have;
quit;
data want;
 set have;
 array x{&max} $ 100;
 do i=1 to countw(text,',');
  x{i}=scan(text,i,',');
 end;
 drop i;
run;
Super User
Posts: 6,936

Re: Single column to multiple column of comma separated

Do you need to split the values into multiple columns, or into a single column in multiple rows?

(I'd prefer the second format)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 3 replies
  • 167 views
  • 0 likes
  • 4 in conversation