BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
goverdhan39
Calcite | Level 5
I have 2 datasets with data
Ds1
1
2
3
Ds2
4
5
6

And I want output like below :
1
4
2
5
3
6

Can anyone help me out for this problem
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ah ok. Do like this instead.

 

data ds1;
input x @@;
datalines;
1 2 3
;

data ds2;
input x @@;
datalines;
4 5 6
;

data want;
   do i=1 to max(nobs1,nobs2);
      set ds1 nobs=nobs1 point=i; output;
      set ds2 nobs=nobs2 point=i; output;
   end;
   stop;
run;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Assuming the variables have the same name (In this example x)

 

data ds1;
input x @@;
datalines;
1 2 3
;

data ds2;
input x @@;
datalines;
4 5 6
;

data want;
   set ds1 ds2;
run;
goverdhan39
Calcite | Level 5
Hi

But for your sol the output will be like

1
2
3
4
5
6

But I need the output like below
1
4
2
5
3
6

Which is taking first observation from Ds1 and first observation from Ds2 like that it follows
PeterClemmensen
Tourmaline | Level 20

Ah ok. Do like this instead.

 

data ds1;
input x @@;
datalines;
1 2 3
;

data ds2;
input x @@;
datalines;
4 5 6
;

data want;
   do i=1 to max(nobs1,nobs2);
      set ds1 nobs=nobs1 point=i; output;
      set ds2 nobs=nobs2 point=i; output;
   end;
   stop;
run;
goverdhan39
Calcite | Level 5
thanks dude
novinosrin
Tourmaline | Level 20
data ds1;
input x @@;
datalines;
1 2 3
;

data ds2;
input x @@;
datalines;
4 5 6
;

data want(keep=x);
set ds1; set ds2(rename=(x=x1));
output;
x=x1;
output;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 6 replies
  • 1573 views
  • 0 likes
  • 3 in conversation