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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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