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
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;
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;
Or a SQL cartesian join:
proc sql;
select a.*, b.*
from a, b
;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.