DATA Step, Macro, Functions and more

Splitting of column values based on number of values.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Splitting of column values based on number of values.

Hi,

I have a dataset in which a column consist more than on value. I would like to split the column as per the number of values(As shown in the expected output).

 

 

                   B

Agriculture     417,859
Power            0059
Real Estate    0038,622
Roads            3243
Telecom         0041

 

Expected Output

 

                   B

Agriculture      417

Agriculture      859

Power            0059

Real Estate    0038

Real Estate    622

Roads            3243

Telecom         0041

 

Thanks in Advance


Accepted Solutions
Solution
‎01-18-2016 04:28 AM
Super User
Posts: 6,936

Re: Splitting of column values based on number of values.

data want;
set have (rename=(B=oldB));
value_count = countw(oldB,',');
do i = 1 to value_count;
  B = scan(oldB,i,',');
  output;
end;
keep A B;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎01-18-2016 04:28 AM
Super User
Posts: 6,936

Re: Splitting of column values based on number of values.

data want;
set have (rename=(B=oldB));
value_count = countw(oldB,',');
do i = 1 to value_count;
  B = scan(oldB,i,',');
  output;
end;
keep A B;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

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

Discussion stats
  • 1 reply
  • 177 views
  • 0 likes
  • 2 in conversation