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

If you have two datasets:

 


data dataset1;
infile datalines;
input Date ;
datalines;
20150130
20150131
20150201
20150202
20150203
20150204
20150205
;
run;

data dataset2;
infile datalines;
input Symbol $ ;
datalines;
AAA
AAB
AAC
AAD
AAE
AAF
AAG
;
run;

 

How would you combine them to get i.e. the resulting dataset will have N(dataset1 rows)*M(dataset2 rows) rows

 

DateSymbol
20150130AAA 
20150131AAA 
20150201AAA 
20150202AAA 
20150203AAA 
20150204AAA 
20150205AAA 
20150130AAB 
20150131AAB 
20150201AAB 
20150202AAB 
20150203AAB 
20150204AAB 
20150205AAB 
20150130AAC 
20150131AAC 
20150201AAC 
20150202AAC 
20150203AAC 
20150204AAC 
20150205AAC 
20150130AAD 
20150131AAD 
20150201AAD 
20150202AAD 
20150203AAD 
20150204AAD 
20150205AAD 
20150130AAE 
20150131AAE 
20150201AAE 
20150202AAE 
20150203AAE 
20150204AAE 
20150205AAE 
20150130AAF
20150131AAF
20150201AAF
20150202AAF
20150203AAF
20150204AAF
20150205AAF
20150130AAF
20150131AAF
20150201AAF
20150202AAF
20150203AAF
20150204AAF
20150205AAF

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use a SQL CROSS JOIN. 

 

SELECT a., b.*

from have as a, have2 as b

 

OR

Select a.*, b.*

from have as a

cross join have2 as b 

View solution in original post

2 REPLIES 2
Reeza
Super User

Use a SQL CROSS JOIN. 

 

SELECT a., b.*

from have as a, have2 as b

 

OR

Select a.*, b.*

from have as a

cross join have2 as b 

Mokben
Fluorite | Level 6

This work (Macro language with SAS 😞 

 


%Macro test_merge() ;
%Do i = 1 %to 7 ;
data data&i. ;
Set dataset2 ;
If _N_ = &i. ;
run ;

data data&i. ;
set data&i.
%do j = 2 %to 7 ;
data&i.
%end ; ;
run ;

Data total&i. ;
merge dataset1 data&i. ;
run ;
%End;

Data total ;
Set total: ;
run ;

%mend ;

%test_merge() ;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 982 views
  • 1 like
  • 3 in conversation