BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dincooo
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
MINX
Obsidian | Level 7

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;
	

View solution in original post

2 REPLIES 2
MINX
Obsidian | Level 7

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;
	
novinosrin
Tourmaline | Level 20
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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1052 views
  • 0 likes
  • 3 in conversation