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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.