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

I have a dataset with 2 columns and 10 rows like this:

student marks
a  10
b  40
c  39
d  45
e  78
f  65
g  38
h  87
i   98
j  29

I have another single row dataset with 5 columns-

col1 col2 col3 col4 col5
m     k       g      h     s

Now I want to merge both the datasets in such a way that the single row of dataset 2 is joined alongside each row of dataset 1 .The final dataset may look like this:

student marks col1 col2 col3 col4 col5
a 10 m k g h s
b 40 m k g h s
c 39 m k g h s
d 45 m k g h s
e 78 m k g h s
f 65 m k g h s
g 38 m k g h s
h 87 m k g h s
i 98 m k g h s
j 29 m k g h s

 

How do I achieve this. I am working on base sas. Please help

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Here is one way

 

data a;
input student $ marks;
datalines;
a  10
b  40
c  39
d  45
e  78
f  65
g  38
h  87
i  98
j  29
;

data b;
input (col1-col5)(:$);
datalines;
m k g h s
;

data want;
   set a;
   if _N_ = 1 then set b;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Here is one way

 

data a;
input student $ marks;
datalines;
a  10
b  40
c  39
d  45
e  78
f  65
g  38
h  87
i  98
j  29
;

data b;
input (col1-col5)(:$);
datalines;
m k g h s
;

data want;
   set a;
   if _N_ = 1 then set b;
run;
LinusH
Tourmaline | Level 20

Or a SQL cartesian join:

proc sql;
   select a.*, b.*
      from a, b
   ;
quit;
Data never sleeps

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 733 views
  • 0 likes
  • 3 in conversation