DATA Step, Macro, Functions and more

Merging SAS data

Reply
Occasional Contributor
Posts: 12

Merging SAS data

[ Edited ]
 
Super User
Posts: 5,920

Re: Merging SAS data

And what is the rule for imputation?
Can't really see that id is something you can impute...?
Data never sleeps
Occasional Contributor
Posts: 12

Re: Merging SAS data

By I'd I have to impute. If I do right merge blanks will come(ref:table2 )
instead blanks I want table 1 values.
Super User
Posts: 5,920

Re: Merging SAS data

Well you need some kind of rule unless you are happy with randomly assigning of values, which in my mind makes the data useless.
Data never sleeps
Occasional Contributor
Posts: 12

Re: Merging SAS data

Let's consider only I'd variable from both the tables. If I do right merge
then I will get complete right table(ref: table 2) alons with blanks. But
instead of blanks iam looking values of table 1 (assumption: both the table
has same values).
Super User
Posts: 10,600

Re: Merging SAS data

Programs are the transformation of rules into computer language. No rule, no program.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 4,797

Re: Merging SAS data

@Naveen1

Let's assume your table1 would also have an ID of 10. Which row/value from the existing table2 would you pick? And why?

Super User
Posts: 24,026

Re: Merging SAS data


table1;                                        

 

Id weight
1 22
2 18
3 23
4 19
5 12
6 20
7 22
8 20
9 12

 

table 2:

Id height
. 76
. 45
. 23
9 11
8 12
4 89
3 43
2 66
1 34

 

Code I have used is, 

data table3;
merge table1(in=x) table2(in=y);
by id;
IF y;
run;

 

my output expectation is :

Id height weight
5 76 12 <- What was the rule for this? 
6 45 20
7 23 22
9 11 12
8 12 20
4 89 19
3 43 23
2 66 18
1 34 22
 

 

 


How did you decide that the first record in Table 2 would be ID 5?

 

Occasional Contributor
Posts: 12

Re: Merging SAS data

It's just assumption (that is how I was expecting output). My question is
to replace missing values by using merge statement (u can ignore height and
weight variable) consider only I'd variable.
Super User
Posts: 10,600

Re: Merging SAS data

On which rule is your assumption based? Without a rule, there will be no programmatic solution, and you can use a random generator or just throw the dice.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 24,026

Re: Merging SAS data


Naveen1 wrote:
It's just assumption (that is how I was expecting output).


We're not in your head. We see only exactly what you post. A computer can only do what you tell it. So what are you telling it to do? 

As someone else stated earlier, you need rules to turn into coded logic. Right now it just seems random, so is that ok randomly assigning the values? Is it ok to have the following output? If not, how do *I*, not you, know it's wrong? Is there a rule. If the rule is only in your head, the only solution is to literally type out each rule manually. 

Is this output ok?

 

Id height weight
5 23 12
6 45 20
7 76 22
9 11 12
8 12 20
4 89 19
3 43 23
2 66 18
1 34 22

 

Super User
Super User
Posts: 8,287

Re: Merging SAS data

[ Edited ]

Why did you match ID=., HEIGHT=76 with ID=5, WEIGHT=12 instead of matching it to one of the other weight records there were not in the height file? ID=6 or ID=7?

Occasional Contributor
Posts: 12

Re: Merging SAS data

no need of solution, it has some mistake in the question

Ask a Question
Discussion stats
  • 12 replies
  • 241 views
  • 0 likes
  • 6 in conversation