[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Problem with comparing a value to a range
From:       Peter Flom <peterflomconsulting () MINDSPRING ! COM>
Date:       2013-06-26 11:09:27
Message-ID: 009a01ce725d$9fe2a9c0$dfa7fd40$ () mindspring ! com
[Download RAW message or body]

That's a cool idea!

Thanks

Peter
-----Original Message-----
From: S øren Lassen [mailto:s.lassen@POST.TELE.DK]
Sent: Wednesday, June 26, 2013 1:58 AM
To: SAS-L@LISTSERV.UGA.EDU; Peter Flom
Subject: Re: Problem with comparing a value to a range

Peter,
if you do not have negative numbers in the data, you can simply use the
minus sign as a delimiter, making the initial read a bit simpler:
data test;
  length _dummy_ $1 min1-min4 max1-max4 8;
  drop _dummy_;
  retain min1--max4;
  infile temp dsd delimiter='|-' truncover;
  if _N_=1 then do;
    input _dummy_ min1 max1 min2 max2 min3 max3 min4 max4;
    input;
    end;
  input id v1 v2 v3 v4;
  /* then do the calculations */

Regards,
Søren


On Mon, 24 Jun 2013 17:24:20 -0400, Peter Flom
<peterflomconsulting@MINDSPRING.COM> wrote:

>Cool! Thanks!
>
>Peter
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Tom Abernathy
>Sent: Monday, June 24, 2013 4:40 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Problem with comparing a value to a range
>
>Read the ranges as text and parse to get min and max.
>You can use _N_=1 processing to read the header with the ranges.
>What you posted did not look like a CSV file, more like a tab delimited
file
>that had been mangled by word processor or email system.  I converted
>it
to
>pipe delimited to make it easier to post.
>
>Opt|7.35-7.45|4.5-8|5.6-7.9|0
>ID|V1|V2|V3|V4
>1|7.3|5.5|7.6|218
>10|7.8|4.8|6|480
>50|7.36|5.2|5.4|104
>
>Here is a program that uses arrays to process. You might get cleaner
>code
if
>you convert to using a more vertical format.
>
>I made an assumption that you wanted the distance to be zero when the
>is within the range.
>
>%let nvars=4;
>
>data ranges ;
>  infile tmpfile1 dsd dlm='|' truncover;
>  length id $8 item 8 value 8 range $20 ;
>  array mins (&nvars)  ;
>  array maxs (&nvars)  ;
>  array ranges (&nvars) $20 ;
>  array v (&nvars) ;
>  array distance (&nvars) ;
>  retain mins1-mins&nvars maxs1-maxs&nvars ranges1-ranges&nvars;
>  if _n_=1 then do;
>    input range  @;
>    do item=1 to &nvars ;
>   input range @;
>   ranges(item)=range;
>      mins(item) = input(scan(range,1,'-'),20.);
>   maxs(item) = input(scan(range,-1,'-'),20.);  end;  input / ;
>  end;
>  input id @ ;
>  do item=1 to &nvars ;
>    input value @;
> v(item)=value ;
> if mins(item) <= value <= maxs(item) then distance(item)=0;  else
>distance(item) = min( abs(mins(item) - value) , abs(maxs(item)
>- value)) ;
>  end;
>  drop item range value ;
>run;
>proc print; run;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic