I need to create a new record if multiple values are available in id column.
Input:
| id | name | city |
| 1 | abc | mumbai |
| 2 | def/jkl | pune |
| 3 | mnop | Delhi |
Required Output:
| id | name | city |
| 1 | abc | mumbai |
| 2 | def | pune |
| 2 | jkl | pune |
| 3 | mnop | Delhi |
Thanks..!!
Hi @prajakta ,
try this:
data have;
input id name $ city $;
cards;
1 abc Mumbai
2 def/jkl Pune
3 mnop Delhi
;
run;
data want (rename=(n=name));
set have;
n = name;
_N_ = countw(n, "/");
do _N_ = 1 to _N_;
name = scan(n, _N_, "/");
output;
end;
drop n;
run;
proc print;
run;All the best
Bart
You need:
If you want code, post data in usable form.
Hi @prajakta ,
try this:
data have;
input id name $ city $;
cards;
1 abc Mumbai
2 def/jkl Pune
3 mnop Delhi
;
run;
data want (rename=(n=name));
set have;
n = name;
_N_ = countw(n, "/");
do _N_ = 1 to _N_;
name = scan(n, _N_, "/");
output;
end;
drop n;
run;
proc print;
run;All the best
Bart
Thanks..!! it works for me...
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.