<?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: Selecting Data (Based on Flight Waypoints) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626337#M184721</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp; To my mind, it does seem you are in the right track to think of SQL. Am i understanding the req correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (flt_biz_uid	msg_biz_uid	flt_pt_code) (:$20.);
cards;
37532375	2859985831	IGN
37532375	2859985832	BETBE
37532375	2859985833	KSFO
37532375	2859985834	KJFK
37532375	2859985835	ZORUN
37532375	2859985836	GALLI
37532375	2859985837	ORRCA
37532375	2859985838	PRNCE
37532375	2859985839	LORAH
37532375	2859985840	RUBKI
37532375	2859985841	DAYYY
37532375	2859985842	SIKBO
37532375	2859985843	TULEG
37532375	2859985844	RAP
37532375	2859985845	CZI
37532375	2859985846	BOY
37532375	2859985847	MLD
;


%let select_flightpoints='RUBKI', 'SIKBO', 'TULEG';

proc sql;
create table want as
select *
from have
where flt_biz_uid in (select flt_biz_uid from have where flt_pt_code in (&amp;amp;select_flightpoints))
order by flt_biz_uid,msg_biz_uid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;P&gt;Should all&amp;nbsp;&amp;nbsp;select_flightpoints be strictly present then , the below SQL version should suffice&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let select_flightpoints='RUBKI', 'SIKBO', 'TULEG';
proc sql;
create table want as
select *
from have 
where  flt_biz_uid in 
(select flt_biz_uid 
from have 
where flt_pt_code in (&amp;amp;select_flightpoints)
group by flt_biz_uid
having count(distinct flt_pt_code)=countw("&amp;amp;select_flightpoints",','));
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 21 Feb 2020 00:45:19 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-02-21T00:45:19Z</dc:date>
    <item>
      <title>Selecting Data (Based on Flight Waypoints)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626331#M184718</link>
      <description>&lt;P&gt;I have raw flight data that I need to make selections from. Each flight is assigned a unique flt_biz_uid.&amp;nbsp; Each flight can have many messages (msg_biz_uid) based on a flight plan. A message can contain a waypoint (flt_pint_code). A paired down flightplan for one flight is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;flt_biz_uid&lt;/TD&gt;&lt;TD&gt;msg_biz_uid&lt;/TD&gt;&lt;TD&gt;flt_pt_code&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985831&lt;/TD&gt;&lt;TD&gt;IGN&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985832&lt;/TD&gt;&lt;TD&gt;BETBE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985833&lt;/TD&gt;&lt;TD&gt;KSFO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985834&lt;/TD&gt;&lt;TD&gt;KJFK&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985835&lt;/TD&gt;&lt;TD&gt;ZORUN&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985836&lt;/TD&gt;&lt;TD&gt;GALLI&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985837&lt;/TD&gt;&lt;TD&gt;ORRCA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985838&lt;/TD&gt;&lt;TD&gt;PRNCE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985839&lt;/TD&gt;&lt;TD&gt;LORAH&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985840&lt;/TD&gt;&lt;TD&gt;RUBKI&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985841&lt;/TD&gt;&lt;TD&gt;DAYYY&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985842&lt;/TD&gt;&lt;TD&gt;SIKBO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985843&lt;/TD&gt;&lt;TD&gt;TULEG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985844&lt;/TD&gt;&lt;TD&gt;RAP&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985845&lt;/TD&gt;&lt;TD&gt;CZI&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985846&lt;/TD&gt;&lt;TD&gt;BOY&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;37532375&lt;/TD&gt;&lt;TD&gt;2859985847&lt;/TD&gt;&lt;TD&gt;MLD&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This goes on for millions of flights.&amp;nbsp; I would like to be able to pick out flt_biz_uids that have specific routes (waypoints). If the above was the complete dataset, and if I wanted to pull out flights that included RUBKI, SIKBO, and TULEG, then ALL of the data above would be pulled. Had I wanted, say, SNOOPY1, SNOOPY2, SNOOPY3 from the above dataset example, then nothing would be returned. I am thinking this maybe SQL?&amp;nbsp; Not sure.&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 20:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626331#M184718</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2020-02-20T20:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Data (Based on Flight Waypoints)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626337#M184721</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp; To my mind, it does seem you are in the right track to think of SQL. Am i understanding the req correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (flt_biz_uid	msg_biz_uid	flt_pt_code) (:$20.);
cards;
37532375	2859985831	IGN
37532375	2859985832	BETBE
37532375	2859985833	KSFO
37532375	2859985834	KJFK
37532375	2859985835	ZORUN
37532375	2859985836	GALLI
37532375	2859985837	ORRCA
37532375	2859985838	PRNCE
37532375	2859985839	LORAH
37532375	2859985840	RUBKI
37532375	2859985841	DAYYY
37532375	2859985842	SIKBO
37532375	2859985843	TULEG
37532375	2859985844	RAP
37532375	2859985845	CZI
37532375	2859985846	BOY
37532375	2859985847	MLD
;


%let select_flightpoints='RUBKI', 'SIKBO', 'TULEG';

proc sql;
create table want as
select *
from have
where flt_biz_uid in (select flt_biz_uid from have where flt_pt_code in (&amp;amp;select_flightpoints))
order by flt_biz_uid,msg_biz_uid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;P&gt;Should all&amp;nbsp;&amp;nbsp;select_flightpoints be strictly present then , the below SQL version should suffice&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let select_flightpoints='RUBKI', 'SIKBO', 'TULEG';
proc sql;
create table want as
select *
from have 
where  flt_biz_uid in 
(select flt_biz_uid 
from have 
where flt_pt_code in (&amp;amp;select_flightpoints)
group by flt_biz_uid
having count(distinct flt_pt_code)=countw("&amp;amp;select_flightpoints",','));
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2020 00:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626337#M184721</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-21T00:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Data (Based on Flight Waypoints)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626339#M184722</link>
      <description>&lt;P&gt;If the table is not sorted, something like this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select a.*
  from TAB a                                    
      ,TAB b                                    
      ,TAB c                                    
      ,TAB d
  where b.FLT_PT_CODE = 'SNOOPY1'
    and c.FLT_PT_CODE = 'SNOOPY2'
    and d.FLT_PT_CODE = 'SNOOPY3'
    and a.FLT_BIZ_UID = b.FLT_BIZ_UID 
    and a.FLT_BIZ_UID = c.FLT_BIZ_UID 
    and a.FLT_BIZ_UID = d.FLT_BIZ_UID ;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it is sorted, there may be faster methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 20:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626339#M184722</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-20T20:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Data (Based on Flight Waypoints)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626370#M184739</link>
      <description>&lt;P&gt;If the data is sorted by flt_biz_uid then do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let select_flightpoints=RUBKI SIKBO TULEG;

data want;
array sf{*} &amp;amp;select_flightpoints;

do until(last.flt_biz_uid); 
	set have; by flt_biz_uid;
	do i = 1 to dim(sf);
		if flt_pt_code = vname(sf{i}) then sf{i} = 1;
		end;
	end;
do until(last.flt_biz_uid); 
	set have; by flt_biz_uid;
	if sum(of sf{*}) = dim(sf) then output;
	end;
drop i &amp;amp;select_flightpoints;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 22:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626370#M184739</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-02-20T22:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Data (Based on Flight Waypoints)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626384#M184747</link>
      <description>&lt;P&gt;If your data are sorted by here's a proof-of-concept for the Data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=nfound);
  set have (where=  flt_pt_cod in ('RUBKI','SIKBO','TULEG') in=foundwaypoints)
      have (in=allwaypoints)
  by FLTBIZ_UID ;

  if first.fltbiz_uid=1 then nfound=0;
  nfound+foundwaypoints;
  if allwaypoints=1 and nfound=3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, this assumes that no waypoint is recorded more than once per flight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assume the SQL solution is more common, but this may well be faster, primarily because it takes advantage of the fact that the data are sorted. &amp;nbsp; So, unlike the SQL solution, it doesn't have to keep somewhere in memory the flight id's of all the flights (both qualifying and not), in case a flight reappears later in the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 02:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Data-Based-on-Flight-Waypoints/m-p/626384#M184747</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-21T02:30:12Z</dc:date>
    </item>
  </channel>
</rss>

