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...
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.