<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to selecet some ID out? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485357#M126089</link>
    <description>Thanks, I will try it later.</description>
    <pubDate>Thu, 09 Aug 2018 07:24:48 GMT</pubDate>
    <dc:creator>xiangpang</dc:creator>
    <dc:date>2018-08-09T07:24:48Z</dc:date>
    <item>
      <title>how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485331#M126077</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to select the IDs with same visit and bmi difference is less than 10%.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;not proc sql. Anyone knows how to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
input id visit bmi ;
cards;
1 day1 45
1 day12 66
1 day60 53
2 day1 45
2 day6 14
2 day12 36
2 day60 83
3 day1 745
3 day12 66
3 day60 50
;
run;

want;
1 day1 45
2 day1 45
1 day12 66
3 day12 66
1 day60 53
3 day60 50&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Aug 2018 02:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485331#M126077</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-09T02:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485333#M126078</link>
      <description>&lt;P&gt;visit should add $&amp;nbsp; , sorry for that&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 02:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485333#M126078</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-09T02:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485338#M126080</link>
      <description>&lt;P&gt;So what if your data contains&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 day1 45&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;day1 49&lt;/P&gt;
&lt;P&gt;3&amp;nbsp;day1 53&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what obs should be selected?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 03:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485338#M126080</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-09T03:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485355#M126087</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194581"&gt;@xiangpang&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, it looks more like a job for SQL, and in all candor, the tool should fit the job, not the other way around.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if you don't want SQL, the job can be done with other means - it's SAS, after all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, as your specs are rather vague, I have to make assumptions, to wit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- If there's only one record in a visit, you don't want the visit in the output; your sample output without DAY6 seems to suggest that, too.&lt;/P&gt;&lt;P&gt;- If there're no BMIs differing by less than 10% in the same visit (not in your sample input data), you don't want that visit in the output, either.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;- No visit has more than 9999 BMI measurements. Methinks it's a reasonable assumption ;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With these assumptions:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new ;                                                     
  input id visit $ bmi ;                                       
  cards ;                                                      
1 day1   45                                                    
1 day12  66                                                    
1 day60  53                                                    
2 day1   45                                                    
2 day6   14                                                    
2 day12  36                                                    
2 day60  83                                                    
3 day1  745                                                    
3 day12  66                                                    
3 day60  50                                                    
run ;                                                          
                                                               
proc sort data = new out = newsort ;                           
  by visit bmi ;                                               
run ;                                                          
                                                               
data want (keep = id visit bmi) ;                              
  array abmi [9999] _temporary_ ;                               
  array aid  [9999] _temporary_ ;                               
  do n = 1 by 1 until (last.visit) ;                           
    set newsort ;                                              
    by visit ;                                                 
    abmi [n] = bmi ;                                           
    aid  [n] = id ;                                            
  end ;                                                        
  if n &amp;gt; 1 then do i = 1 to n - 1 ;                            
    do j = i + 1 to n ;                                        
      if divide (abmi[j] - abmi[i], abmi[j]) &amp;gt; 0.1 then leave ;
      bmi = abmi [i] ; id = aid [i] ; output ;                 
      bmi = abmi [j] ; id = aid [j] ; output ;                 
    end ;                                                      
  end ;                                                        
run ;                                                          &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that the sorting, though not strictly necessary, technically speaking, greatly simplifies the code. Also, it helps avoid comparing ALL BMI measurements within the same visit pairwise since in the sorted BMI sequence, the difference between item [i] and item [i+1] is always no greater than between item [i] and item [i+(&amp;gt;1)].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 07:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485355#M126087</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-09T07:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485356#M126088</link>
      <description>In this case, all three should be included. Since day1 is same, and 49-53 difference is less than 10% while 45-49 difference is less than 10%.</description>
      <pubDate>Thu, 09 Aug 2018 07:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485356#M126088</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-09T07:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485357#M126089</link>
      <description>Thanks, I will try it later.</description>
      <pubDate>Thu, 09 Aug 2018 07:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485357#M126089</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-09T07:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485369#M126099</link>
      <description>&lt;P&gt;Given the brevity of a SQL solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select distinct a.*
from new a, new b
where a.visit = b.visit and a.id ne b.id and abs(a.bmi - b.bmi) &amp;lt;= min(a.bmi,b.bmi) / 10
order by visit,id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;not using it is dumb, IMHO. Unless the performance of SQL because of dataset size is intolerable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 08:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485369#M126099</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-09T08:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485378#M126105</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I doubt your SQL will underperform against a much more sizable input since the optimizer plan for this query uses the SQXJHSH method and doesn't resort to any Cartesian expansions. But even if it did, the simplicity of coding (or, rather, nearly not needing to code) would more than make up for that. To put together a viable DATA step solution in this case, one needs to know infinitely more about procedural programming and think its details out than to write a simple SQL query hardly requiring any programming at all. Like I said, the tool should fit the job, not vice versa. I'm not quite an SQL head; but in this case, it's exactly what the doctor ordered (and my having offered a DATA step solution notwithstanding).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 08:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485378#M126105</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-09T08:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485402#M126111</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Check this code, this could help your need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort;
by visit;
run;

data want (keep = id visit bmi);
set new (rename = (id = id1 visit = visit1 bmi = bmi1));
do i =1 to n;
	set new point = i nobs = n;
 	v = divide(abs(bmi1 - bmi), bmi1);
	if (visit = visit1) &amp;amp; (id ne id1) &amp;amp; v le 0.1 then output  ;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Manoj&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 10:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485402#M126111</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-08-09T10:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to selecet some ID out?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485526#M126157</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183918"&gt;@s_manoj&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code runs a de facto Cartesian product reading every obs from one copy of NEW for every obs in another, and it doesn't even take advantage of the sorted order. Hence, it will scale extremely poorly as the input size grows. At nobs=100000, an efficient solution would run in under a second, yet your program would take good 30 minutes. And at nobs=1000000 (which is a very small data set by today's standards) it would take upward of 50 hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The point= approach could be viable (though still slower than anything else) if you take advantage of the sorted order BY VISIT BMI and (a) use point= to read only the observations between the endpoints of the current BY group and (b) leave the point= loop as soon as the 10% condition is false.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 17:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-selecet-some-ID-out/m-p/485526#M126157</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-09T17:03:53Z</dc:date>
    </item>
  </channel>
</rss>

