0
votes

I am stuck in this one particular point. I have a character variable with observations extracted from rtf document. I need to keep only the observations from obs A to obs B. The firstobs and obs is not helpful here because we do not know the observation number beforehand. All we know is the two unique strings. For example in the dataset, I need to create a dataset with observations from obs 11 to 16. This is only part of dataset, the original dataset has over 1500 observations, that is why we use unique text to capture instead of observation number.

Thank you all in advance.

1
Not sure I follow. Do you just want to do data newdata; set mydata; where myobs between 11 and 16; run; Might help if you posted some sample data.James King
I tried to post an image but the system didn't let me as I am new user here. Let me try to explain it more. My var1 has 1500 observations. My first obs is somewhere around 150 and last obs is somewhere around 750. I know what the first and second observation values are. Now, I need only those observations that is in between these two observations. It is not a numerical value, therefore if/then where clause does not apply.Sammy
Post a simple example - make up a five or six line example, say.Joe
The codes below works fine. Thank you for your input.Sammy

1 Answers

1
votes

You don't explain enough, but odds are you can do something sort of like this if I understand you right (you have a "start" and a "stop" string in the document).

data want;
 set have;
 retain keep 0;
 if strvar = "keepme" then keep=1;
 if keep=1;
 if strvar = "lastone" then keep=0;
run;

IE, have some condition set the keep variable to 1, then test for it, then have the off condition after that (assuming you want to keep the off condition row). Use string functions like index or find or scan to search for your particular string if it's not an entire string. You could also use regular expressions if necessary.