Hi everyne,
Suppose that I have a data like this:
(It shows company A made 4 times transaction to company B, company C made 1 time transaction to company D etc..)
A B 4
C D 1
A E 3
I need to transform this data like this:
ID Target
1 A
1 B
2 A
2 B
3 A
3 B
4 A
4 B
---------4 (A,B)
5 C
5 D
---------1 (C,D)
6 A
6 E
7 A
7 E
8 A
8 E
----------3 (A, E)
How can I do that?
Thank you very much!
Onur
Check out. Hope this is what you want
data have;
input col1 :$ col2 :$ n;
datalines;
A B 4
C D 1
A E 3
;
run;
data want;
set have;
do id=1 to n;
target=col1;
output;
target=col2;
output;
end;
keep id target;
run;
Check out. Hope this is what you want
data have;
input col1 :$ col2 :$ n;
datalines;
A B 4
C D 1
A E 3
;
run;
data want;
set have;
do id=1 to n;
target=col1;
output;
target=col2;
output;
end;
keep id target;
run;
data have;
input var1 $ var2 $ var3;
datalines;
A B 4
C D 1
A E 3
;
data want;
set have;
retain _id;
if _n_=1 then do;
do id =1 to var3;
target=var1;
output;
target=var2;
output;
end;
_id=id;
end;
else do;
do id= _id by 1 until(id=_id+var3-1);
target=var1;
output;
target=var2;
output;
end;
_id=id+1;
end;
keep id target;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.