SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
kundamn0
Calcite | Level 5

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,

5 REPLIES 5
Yavuz
Quartz | Level 8
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;
Ksharp
Super User
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;
SASComm1
Calcite | Level 5

Much appreciated if one can show how to split the values into a single column in multiple rows.

Patrick
Opal | Level 21

@SASComm1 wrote:

Much appreciated if one can show how to split the values into a single column in multiple rows.


See below @Ksharp's sample script repurposed for a single value in multiple rows.

data have;
  text='xx,ee,tt       ';
  output;
  text='jj,ii,ii,kk';
  output;
run;

data want;
  set have;

  do i=1 to countw(text,',');
    text2=scan(text,i,',');
    output;
  end;

  drop i;
run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 5353 views
  • 0 likes
  • 6 in conversation