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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 991 views
  • 0 likes
  • 3 in conversation