data have;
input accid branch;
datalines;
1001 pune,hyderabad,banglore
1002 haryana,delhi
1003 shimla
;
run;
data want;
input accid branch;
datalines;
1001 pune
1001 hyderabad
1001 banglore
1002 haryana
1002 delhi
1003 shimla
;
run;
In line with @andreas_lds:
data have;
input accid $4. branch $25.;
datalines;
1001 pune,hyderabad,banglore
1002 haryana,delhi
1003 shimla
;
run;
data want (drop = branch i);
set have;
do i = 1 to countw(branch, ","); /* i becomes a counter for the commas */
_branch = scan(branch, i, ","); /* notice the i becomes the <count> argument in the SCAN function. The loop iterates over the number of commas.*/
output; /* Output each separate branch before returning to top of loop. */
end;
run;
accid _branch 1001 pune 1001 hyderabad 1001 banglore 1002 haryana 1002 delhi 1003 shimla
Problems like your have asked and answered so many times, i wonder why you haven't found something to adaptable to your needs.
You will have to use:
In line with @andreas_lds:
data have;
input accid $4. branch $25.;
datalines;
1001 pune,hyderabad,banglore
1002 haryana,delhi
1003 shimla
;
run;
data want (drop = branch i);
set have;
do i = 1 to countw(branch, ","); /* i becomes a counter for the commas */
_branch = scan(branch, i, ","); /* notice the i becomes the <count> argument in the SCAN function. The loop iterates over the number of commas.*/
output; /* Output each separate branch before returning to top of loop. */
end;
run;
accid _branch 1001 pune 1001 hyderabad 1001 banglore 1002 haryana 1002 delhi 1003 shimla
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.