10-10-2017 09:55 AM - edited 10-10-2017 10:35 AM
To SAS experts - I have repeated measures data (multiple obs per id) and I am trying to duplicate a variable but only keep values that satisfy a condition:
id x x1
1 1 2
1 2 .
1 2 30
2 1 350
2 2 .
2 2 30
id x x1 x2
1 1 2 2
1 2 . .
1 2 30 .
2 1 350 350
2 2 . .
2 2 30 .
I tried this :
if x1~=. then x2=x1;
SAS deletes all of my other observations and only keeps those that follow the if statement - what do I do?
10-10-2017 10:12 AM
You may need to explain a fuller set of rules then. Take the example in your data where X1 is 3. Why is X2 missing, and not 3?
Could the solution be as simple as this?
x2 = x1;
10-10-2017 10:25 AM
OK, time for full disclosure then. No secrets allowed.
When should X2 be equal to X1?
When should X2 be missing?
Are there any other possibilities?
The programming is easy. You just have to spell out the rules.
10-10-2017 10:36 AM
10-10-2017 10:24 AM
The purpose of this statement is to remove any observation where the value of X1 is other than 2
So you told SAS to delete observations.
Provide a description of the actual rule(s) involved.
10-10-2017 04:02 PM
I only added the where statement so that the if statement executes in those places and the remainder is meant to be missing.
Where does not work that way. Where subsets data given the rules on the statement. It actually works as data is read and does not matter where in the data step the where statement exists. Unless you have multiple where statements, in which case the last one is likely going to be the one in effect.
Need further help from the community? Please ask a new question.