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...
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.