08-14-2014 01:36 AM
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.
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):
3. I try this:
set data.name data.date;
This gives me a table not I want
4. Is there anyway to make the table into the one in step 2?
08-14-2014 04:55 AM
set data.name ;
See: SAS(R) 9.4 Language Reference: Concepts, Third Edition (one-to one reading)
08-14-2014 08:06 AM
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?
08-14-2014 08:15 AM
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:
merge first (in=b) second (in=b);
if a and not b then ....;
if b and not a then ...;
08-14-2014 08:34 AM
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.
08-16-2014 11:02 PM
You can use the MERGE statement without a BY statement to do what you want.
merge one two;
* no by statement;
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.;
input date ddmmyy10. ;
format date yymmdd10. ;