<?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: Select one row for each customer from Tera table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-one-row-for-each-customer-from-Tera-table/m-p/910439#M359041</link>
    <description>&lt;P&gt;This code does all of the work in Teradata and brings back only the desired rows to SAS. It might run faster for you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;  
connect to teradata (server=dwprod schema=DWP_vall authdomain=TeraDataAuth);
create table t_Customer_Segment_b  as 
select * from connection to teradata
(
	select allRows.Branch_Cust_Nbr
		  ,allRows.Branch_Nbr
		  ,Customer_Segment
		  ,DATE_UPDATED_TO_DW
		from V01X997_IP_REGULATORY_ACTIVITY_SEGMENT as allRows
		inner join
		(select Branch_Cust_Nbr
			   ,Branch_Nbr
			   ,max(DATE_UPDATED_TO_DW) as TargetDate
			from V01X997_IP_REGULATORY_ACTIVITY_SEGMENT
			group by Branch_Cust_Nbr
					,Branch_Nbr) as maxDate
		on  allRows.Branch_Cust_Nbr=maxDate.Branch_Cust_Nbr
		and allRows.Branch_Nbr=maxDate.Branch_Nbr
		where DATE_UPDATED_TO_DW=TargetDate
)
;
disconnect from teradata;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Jan 2024 13:12:57 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2024-01-04T13:12:57Z</dc:date>
    <item>
      <title>Select one row for each customer from Tera table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-one-row-for-each-customer-from-Tera-table/m-p/910423#M359038</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to select one row for each customer and this row should be the row with max date (Last date).&lt;/P&gt;
&lt;P&gt;The source table is in Tera but I must run it in SAS.&lt;/P&gt;
&lt;P&gt;Is there a better way to do it in one step?&lt;/P&gt;
&lt;P&gt;Here I did it in 2 steps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;  
connect to teradata (server=dwprod schema=DWP_vall authdomain=TeraDataAuth);
create table t_Customer_Segment  as 
select * from connection to teradata
(
SELECT   Branch_Cust_Nbr,Branch_Nbr,Customer_Segment,DATE_UPDATED_TO_DW
from V01X997_IP_REGULATORY_ACTIVITY_SEGMENT
order by  Branch_Nbr,Branch_Cust_Nbr,DATE_UPDATED_TO_DW desc
);
disconnect from teradata;
quit ;

Data t_Customer_Segment_b;
set t_Customer_Segment;
by Branch_Nbr,Branch_Cust_Nbr;
If first.Branch_Cust_Nbr;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2024 10:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-one-row-for-each-customer-from-Tera-table/m-p/910423#M359038</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-04T10:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select one row for each customer from Tera table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-one-row-for-each-customer-from-Tera-table/m-p/910439#M359041</link>
      <description>&lt;P&gt;This code does all of the work in Teradata and brings back only the desired rows to SAS. It might run faster for you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;  
connect to teradata (server=dwprod schema=DWP_vall authdomain=TeraDataAuth);
create table t_Customer_Segment_b  as 
select * from connection to teradata
(
	select allRows.Branch_Cust_Nbr
		  ,allRows.Branch_Nbr
		  ,Customer_Segment
		  ,DATE_UPDATED_TO_DW
		from V01X997_IP_REGULATORY_ACTIVITY_SEGMENT as allRows
		inner join
		(select Branch_Cust_Nbr
			   ,Branch_Nbr
			   ,max(DATE_UPDATED_TO_DW) as TargetDate
			from V01X997_IP_REGULATORY_ACTIVITY_SEGMENT
			group by Branch_Cust_Nbr
					,Branch_Nbr) as maxDate
		on  allRows.Branch_Cust_Nbr=maxDate.Branch_Cust_Nbr
		and allRows.Branch_Nbr=maxDate.Branch_Nbr
		where DATE_UPDATED_TO_DW=TargetDate
)
;
disconnect from teradata;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2024 13:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-one-row-for-each-customer-from-Tera-table/m-p/910439#M359041</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-01-04T13:12:57Z</dc:date>
    </item>
  </channel>
</rss>

