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

I have 2 datasets one has ID values and i want to merge it with text to get the values from text, i need something like below - want dataset. any help on it

ID
1
2
3
4

 

TEXT
Height
Weight

 

I want something like this

ID TXT
1 Height
1 Weight
2 Height
2 Weight
3 Height
3 Weight
4 Height
4

Weight

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

With a data step.

 

data have1;
input ID;
datalines;
1
2
3
4
;

data have2;
input TEXT $;
datalines;
Height
Weight
;

data want;
   set have1;
   do i=1 to n;
      set have2 point=i nobs=n;
      output;
   end;
run;

 

Result:

 

ID  TEXT 
1   Height 
1   Weight 
2   Height 
2   Weight 
3   Height 
3   Weight 
4   Height 
4   Weight 

View solution in original post

2 REPLIES 2
Aku
Obsidian | Level 7 Aku
Obsidian | Level 7

With Proc SQL you can create cartesian product just (You haven't defined dataset names , so I'm using column names)

Proc Sql;

  create table want as

  select *

  from  ID, TEXT;

quit;

PeterClemmensen
Tourmaline | Level 20

With a data step.

 

data have1;
input ID;
datalines;
1
2
3
4
;

data have2;
input TEXT $;
datalines;
Height
Weight
;

data want;
   set have1;
   do i=1 to n;
      set have2 point=i nobs=n;
      output;
   end;
run;

 

Result:

 

ID  TEXT 
1   Height 
1   Weight 
2   Height 
2   Weight 
3   Height 
3   Weight 
4   Height 
4   Weight 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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