DATA Step, Macro, Functions and more

Needed one output for ds

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Needed one output for ds

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

Accepted Solutions
Solution
3 weeks ago
PROC Star
Posts: 1,400

Re: Needed one output for ds

Posted in reply to goverdhan39

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


All Replies
PROC Star
Posts: 1,400

Re: Needed one output for ds

Posted in reply to goverdhan39

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;
New Contributor
Posts: 4

Re: Needed one output for ds

Posted in reply to goverdhan39
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
Solution
3 weeks ago
PROC Star
Posts: 1,400

Re: Needed one output for ds

Posted in reply to goverdhan39

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;
New Contributor
Posts: 4

Re: Needed one output for ds

thanks dude
PROC Star
Posts: 1,400

Re: Needed one output for ds

Posted in reply to goverdhan39

Anytime Smiley Happy

Super User
Posts: 2,050

Re: Needed one output for ds

Posted in reply to goverdhan39
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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 126 views
  • 0 likes
  • 3 in conversation