08-12-2014 10:32 AM
I know there has to be a super simple way to do this.
I need to create an indicator variable for a large range of contentious and non continuous numbers. In my past I've only had a max of 20 numbers so I just wrote each one in. Lets say for example my numbers are 142-244, 333, and 401-420. How would I do this? I ultimately want to create an indicator variable to say if the previous numbers are there put 1 and if any other number put 0. I've been trying to figure this out for a day and by now i could have typed out the numbers....
Side note, they were originally assigned at characters and I changed it to numbers to try to figure this out.
Thank you for your help,
08-12-2014 10:51 AM
For my number range, I ultimately need to exclude those numbers for certain tables. Also there is not always numbers in between the numbers I want. Like 200 and 205 is missing but I need 142-245.
08-12-2014 10:53 AM
Perhaps post some test data of what you have and what you want. If it is as I think then;
do I=142 to 244;
if thenumber ne I then do;
/* do your code */
08-12-2014 11:29 AM
If I have the correct picture, you have a variable that takes on numeric values and you need to examine this variable to determine whether the current observation should be included or excluded. Does that sound right?
If that's the case, a format is probably the best bet. You can hard-code a format, such as:
value inex 142-144, 333, 401-420 = 'Include' other='Exclude';
Then in a procedure you can use the format, such as:
where put(some_variable, inex.)='Include';
Formats let you handle trickier ranges, such as excluding 200 and 205 specifically. And if your list of values is long but is contained in a data set, formats let you use the data set to construct the format instead of having to type out all the values. Formats can be permanently saved, so they don't have to re-created each time.
So the first question is still, is this the actual problem you are trying to solve?
08-12-2014 12:41 PM
From the subject and your explanation I just understand that
You have a list of continuos and non-continuos number from which you want to set some ranges of continuous values.
Final desired output is just starting range and ending range... this is what i understand, correct me if i am wrong.
And here is my code.....
init = mynum;
if _N_ =1 then start = mynum;
if mynum - prevnum ne 1 then start = init;
prevnum = mynum;
retain start init prevnum;
proc sort data=want; by start; run;
data want(rename=(start=rangest prevnum=rangelt) drop=mynum init);
Obs rangest rangelt
1 142 145
2 333 333
3 401 404
If this is not your desired output, Give us some example data and your desired output!!!!
08-12-2014 01:46 PM
Use the colon operator to specify a range of values and then comma's to separate the different ranges and values.
if age in (12:14, 16);
if number in (142:244, 333, 401:420) then flag=1; else flag=0;