put one all columns in one dataset to another dataset

Reply
New Contributor
Posts: 2

put one all columns in one dataset to another dataset

I am fairly new to SAS. As my sample is quite big. Here I just use a simple example to clarify my problem.

1. I have this two datasets.

Capture2.JPGCapture1.JPG

2. I want to combine them into this format (not merge or join. They have the same length, just simply want to put them together into one dataset):

Capture.JPG

3. I try this:

data data.comnbine;

set data.name data.date;

run;

This gives me a table not I want

Capture3.JPG

4. Is there anyway to make the table into the one in step 2?

Many thanks

New Contributor
Posts: 2

Re: put one all columns in one dataset to another dataset

Solved~

Valued Guide
Posts: 3,206

Re: put one all columns in one dataset to another dataset

data data.comnbine;

set data.name ;

set data.date;

run;

See:  SAS(R) 9.4 Language Reference: Concepts, Third Edition  (one-to one reading)

---->-- ja karman --<-----
Contributor
Posts: 45

Re: put one all columns in one dataset to another dataset

Hi Jaap,

I have learned a new thing that using set statement twice....

However I would like to know Is there any process to handle some missing values in one dataset here?

I mean to say, If 3 obs are there in first dataset and two in second, In that case, how to handle it?

Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: put one all columns in one dataset to another dataset

TBH, and whilst Jaap Karman shows a really nice way of doing it if you have 9.4, I would still assign a merge variable to each, in this case even if it is only _n_, then merge based off that.  You could then do all your logic parts:

data want;

     merge first (in=b) second (in=b);

     by N;

     if a and not b then ....;

     if b and not a then ...;

run;

Valued Guide
Posts: 3,206

Re: put one all columns in one dataset to another dataset

RW9, I gave the 9.4 docs of concepts. But I am remembering this as one of the prehistoric SAS approaches.
The dow-loop is another one playing with the PDV. Another is playing with a pointer to a dataset with direct access.

There were days, SQL was not the first idea.     

---->-- ja karman --<-----
Grand Advisor
Posts: 9,571

Re: put one all columns in one dataset to another dataset

data data.comnbine;

merge data.name data.date;

run;

Xia Keshan

Super User
Super User
Posts: 6,318

Re: put one all columns in one dataset to another dataset

You can use the MERGE statement without a BY statement to do what you want.

data both;

merge one two;

* no by statement;

run;

You could have also solved the problem during the creation of the original data sets by reading both variables at once.

data both ;

   infile one ;

   input name $20.;

   infile two;

   input date ddmmyy10. ;

   format date yymmdd10. ;

run;

Ask a Question
Discussion stats
  • 7 replies
  • 410 views
  • 0 likes
  • 6 in conversation