<?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: Is there a way to upsert to castable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916474#M360980</link>
    <description>But some rows are not duplicate. Like ID 5,7 in public.a and public.b. Its height column has different values. I want ID 5,7 in public.c have the value from public.b.</description>
    <pubDate>Fri, 16 Feb 2024 14:21:11 GMT</pubDate>
    <dc:creator>Mayt</dc:creator>
    <dc:date>2024-02-16T14:21:11Z</dc:date>
    <item>
      <title>Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916417#M360963</link>
      <description>&lt;P&gt;Hi guys!&lt;/P&gt;
&lt;P&gt;I've tried to update and insert new data to castable. But My code takes a lot of time to complete. Do you guys know how to use upsert by any chance? Or how to optimise my code?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot!!&lt;/P&gt;
&lt;P&gt;My code right now:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data public.A;
Input ID Name$ Height;
cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

Data public.B;
Input ID Name$ Height;
cards;
2 A 2
4 B 3
5 C 4
7 D 5
;
run;
/* select all rows from public.a and flag rows that exist in both public.a, public.b */
proc fedsql sessref=MySession;
create table public.C as 
select x.*,case when y.ID is not null then 1 else 0 end as flag
from public.a x 
left join public.b y
on x.ID = y.ID;
quit;
/* delete rows that exist in both public.a, public.b from public.c*/
proc cas;
table.deleteRows                    
table={caslib='public',
name='c',
where="flag = 1"};
quit;
/* drop column flag*/
proc cas;
table.alterTable / 
	name = 'c', caslib ='public', 
	drop={'flag'};
quit;

/* appending new data to the base */
data public.c (append=yes);
set public.b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;public.a&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mayt_0-1708072715547.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93819iFF78A4EE2086E028/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mayt_0-1708072715547.png" alt="Mayt_0-1708072715547.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;public.b&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mayt_1-1708072768474.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93820i022429281B874350/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mayt_1-1708072768474.png" alt="Mayt_1-1708072768474.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;public.c&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mayt_2-1708072970952.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93821i0088AFB42B2EE98D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mayt_2-1708072970952.png" alt="Mayt_2-1708072970952.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 08:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916417#M360963</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-16T08:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916430#M360970</link>
      <description>&lt;P&gt;I don't see update in your logic, just insert of new records...?&lt;BR /&gt;Not a CAS specific advice: try to reduce number of steps. &lt;BR /&gt;Instead of a left join an flag creation, try a where clause with sub-query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where c.id not in(select distinct id from public.b)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then and insert/append.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 12:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916430#M360970</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-02-16T12:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916432#M360972</link>
      <description>&lt;P&gt;Append + de-duplicate??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;APPEND :&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;The SAS® Viya® platform provides multiple methods to append to CAS tables &lt;BR /&gt;By Kevin Russell on SAS Users November 6, 2023&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2023/11/06/sas-viya-append-cas-tables/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sgf/2023/11/06/sas-viya-append-cas-tables/&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;How to Emulate PROC APPEND in CAS? &lt;BR /&gt;By Steven Sober on SAS Users November 20, 2017&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2017/11/20/how-to-emulate-proc-append-in-cas/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sgf/2017/11/20/how-to-emulate-proc-append-in-cas/&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Concurrent data append and update to a global CAS table &lt;BR /&gt;By Uttam Kumar on SAS Users November 15, 2017&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2017/11/15/concurrent-data-append-and-update-to-a-global-cas-table/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sgf/2017/11/15/concurrent-data-append-and-update-to-a-global-cas-table/&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;DE-DUPLICATE :&lt;BR /&gt;&lt;SPAN&gt;You can use the native&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/default/caspg/cas-deduplication-deduplicate.htm?fromDefault=" target="_blank" rel="noopener"&gt;deduplication.deduplicate&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;CAS action to remove duplicate rows.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 13:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916432#M360972</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-02-16T13:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916439#M360975</link>
      <description>I think I need to update. You see ID 5,7 the height value of public.a(old&lt;BR /&gt;data) and public.b(new data) are different. I want to store the value from&lt;BR /&gt;public.b&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Feb 2024 13:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916439#M360975</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-16T13:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916451#M360977</link>
      <description>&lt;P&gt;Oh I see your point. But when I tried it, look like fedsql doesn't support in/any/all subquery.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fedsql sessref=MySession;
create table public.C as 
select *
from public.a x 
where x.id not in(select distinct id from public.b);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It thew an error&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;ERROR: Unsupported operation in FedSQL query: IN/ANY/ALL subquery.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 16 Feb 2024 13:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916451#M360977</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-16T13:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916462#M360978</link>
      <description>More information : I code in SAS studio of SAS Viya</description>
      <pubDate>Fri, 16 Feb 2024 14:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916462#M360978</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-16T14:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916466#M360979</link>
      <description>&lt;P&gt;Indeed,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FedSQL for CAS does not support use of non-correlated subqueries with the IN, ANY, and ALL predicates.&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/casfedsql/p1ucns3lrhzhamn1k6fw6vhzhzam.htm" target="new"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/casfedsql/p1ucns3lrhzhamn1k6fw6vhzhzam.htm&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can try to do an alternate query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 14:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916466#M360979</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-02-16T14:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916474#M360980</link>
      <description>But some rows are not duplicate. Like ID 5,7 in public.a and public.b. Its height column has different values. I want ID 5,7 in public.c have the value from public.b.</description>
      <pubDate>Fri, 16 Feb 2024 14:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916474#M360980</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-16T14:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916511#M360987</link>
      <description>&lt;P&gt;Appreciate that you're sharing code with sample data that we can run to replicate what you describe.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe in your case we need to better understand what you've got in your real environment.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Does the target CAS table public.C preexist in CAS? And what's the volume (number of rows)&lt;/P&gt;
&lt;P&gt;2. Do you really have two source tables public.A and public.B? Or is this "just" about how to update/insert into a CAS target table and though you would in reality only have a single source table?&lt;/P&gt;
&lt;P&gt;3. Where do your source table(s) reside? In CAS or in Compute? And what are the volumes (number of rows).&lt;/P&gt;
&lt;P&gt;4. Once you've updated the in-memory CAS table do you also need to save back the changes to the physical table? And if so: Where is this physical table stored?&lt;/P&gt;
&lt;P&gt;5. Which Viya version are you using?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 16:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916511#M360987</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-16T16:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916726#M361090</link>
      <description>&lt;P&gt;1. Does the target CAS table public.C preexist in CAS? And what's the volume (number of rows)&lt;BR /&gt;- Nope, Actually it's used for store merged data from table A(old data) and table B (new data).&lt;/P&gt;
&lt;P&gt;2. Do you really have two source tables public.A and public.B? Or is this "just" about how to update/insert into a CAS target table and though you would in reality only have a single source table?&lt;BR /&gt;- I do have two source table. In my real code, I have table A and table D. Then I copy data from table D to Table B to rename columns.&lt;/P&gt;
&lt;P&gt;3. Where do your source table(s) reside? In CAS or in Compute? And what are the volumes (number of rows).&lt;BR /&gt;- In CAS. table A has 45 million row, table B has 1000-10000 rows.&lt;BR /&gt;4. Once you've updated the in-memory CAS table do you also need to save back the changes to the physical table? And if so: Where is this physical table stored?&lt;BR /&gt;- In CAS. Actually it's table A.&lt;BR /&gt;5. Which Viya version are you using?&lt;BR /&gt;- 2022.09 and 2022.1&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 03:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916726#M361090</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-19T03:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916732#M361093</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439882"&gt;@Mayt&lt;/a&gt;&amp;nbsp;Given your answers and that you're creating table C couldn't you just use a data merge step?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sessref=MySess;
%if %sysfunc(sessfound(&amp;amp;sessref)) %then
  %do;
    cas mySess terminate;
  %end;
cas &amp;amp;sessref cassessopts=(caslib="casuser");
libname casuser cas;

data casuser.A;
  input ID Name $ Height;
cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

data casuser.B;
  input ID Name $ Height;
cards;
2 A 2
4 B 3
5 C 4
7 D 5
;
data casuser.c;
  merge casuser.a casuser.b;
  by id;
run;

proc print data=casuser.c;
  where id in (1,2,5);
run;

/*cas &amp;amp;sessref terminate;*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With all tables in CAS the data step will execute in CAS&lt;/P&gt;
&lt;PRE&gt;08  data casuser.c;
109    merge casuser.a casuser.b;
110    by id;
111  run;
NOTE: Running DATA step in Cloud Analytic Services.
NOTE: The DATA step will run in multiple threads.
NOTE: There were 5 observations read from the table A in caslib CASUSER(&amp;lt;user&amp;gt;).
NOTE: There were 4 observations read from the table B in caslib CASUSER(&amp;lt;user&amp;gt;).
NOTE: The table c in caslib CASUSER(&amp;lt;user&amp;gt;) has 7 observations and 3 variables.&lt;/PRE&gt;
&lt;P&gt;Given the volume of your table A:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Not sure how this code will perform. Let us know.&lt;/LI&gt;
&lt;LI&gt;Either drop table A after this process from memory or also define it as output of the merge step so the process replaces table A (to save some memory).
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data casuser.a;
  merge casuser.a casuser.b;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;N.B: The ID column used for BY processing may-not be defined as VARCHAR(*). Let us know should this be the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 05:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916732#M361093</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-19T05:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916746#M361095</link>
      <description>&lt;P&gt;Due to enormous data, I'm afraid that data step might take longer time than fedsql.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 07:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916746#M361095</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-19T07:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916772#M361108</link>
      <description>&lt;P&gt;The "problem" here is that CAS is mainly built for&amp;nbsp; analytics, not for DB operations.&lt;/P&gt;
&lt;P&gt;Which we can see in the syntax limitations of PROC FEDSQL, data step and PROC CASL.&lt;/P&gt;
&lt;P&gt;3.) So B would have 45'' records after the operation?&lt;/P&gt;
&lt;P&gt;Is this repeated, like daily?&lt;/P&gt;
&lt;P&gt;What is your pain point, from a user and/or maintenance perspective?&lt;/P&gt;
&lt;P&gt;Again (partly) untested, but if you have avialable RAM, you could possible overcome limitations of UPDATE, recreate the table using a FEDSQL join query&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fedsql sessref=MySession;
create table public.C as 
	select 
		coalesce(x.id,y.id) as id, 
		coalesce(x.name, y.name) as name, 
		coalesce(x.height, y.height) as height
	from public.a x 
	full join public.b y
	on x.ID = y.ID;

drop table public.b;
quit;
/* renaming back to 'B' */
proc casutil...
altertable...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2024 12:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916772#M361108</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-02-19T12:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916780#M361111</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439882"&gt;@Mayt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Due to enormous data, I'm afraid that data step might take longer time than fedsql.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439882"&gt;@Mayt&lt;/a&gt;&amp;nbsp;What makes you think that? The data step will execute multithreaded within CAS - as a CAS action. The main challenge is that you create a new in-memory CAS table that's then also no more in-synch with the physical backing table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's most of the time better to do data prep before loading the data into CAS and only load the final table server side into CAS. To propose any such approach we would need to understand more about your scenario, where the data comes from, how often you have to update it in CAS and what it gets used for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2024 13:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916780#M361111</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-19T13:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916927#M361176</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;where the data comes from?&lt;/STRONG&gt;&lt;BR /&gt;- new data comes from API. &lt;BR /&gt;It's like new data comes from API --&amp;gt; update to old data --&amp;gt; feed to the model and save data(from 2) as physical file to sas.&lt;BR /&gt;&lt;STRONG&gt;how often you have to update it in CAS?&lt;/STRONG&gt;&lt;BR /&gt;- every 20 minutes&lt;BR /&gt;&lt;STRONG&gt;what it gets used for?&lt;/STRONG&gt;&lt;BR /&gt;- use as input to train model.&lt;BR /&gt;&lt;STRONG&gt;What is your pain point, from a user and/or maintenance perspective?&lt;/STRONG&gt;&lt;BR /&gt;- due to the circle need to repeat every 20 minutes, sometimes the data can't be updated completely before feed to model. So I need to wait next round to complete it. But I want to finish it within each round. That's why I think if there's a way to update data faster, that might be great.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 08:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916927#M361176</guid>
      <dc:creator>Mayt</dc:creator>
      <dc:date>2024-02-20T08:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916934#M361180</link>
      <description>&lt;P&gt;For each answer I get more questions, like what does the model to with the data it gets fed by every 20 minutes?&lt;/P&gt;
&lt;P&gt;What kind of API calls are there? Sounds more like a stream, but those typically doesn't have updates.&lt;/P&gt;
&lt;P&gt;Updates typically belongs to a relational database platform.&lt;/P&gt;
&lt;P&gt;So, it sounds like a complex use case, and I think you need someone at your site to guide you to a functioning design for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 10:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916934#M361180</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-02-20T10:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to upsert to castable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916944#M361182</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439882"&gt;@Mayt&lt;/a&gt;&amp;nbsp;In below sample code table A is your big table with 45 Million rows and table B is your transaction table with 1T to 10T rows used to upsert table A.&lt;/P&gt;
&lt;P&gt;There is unfortunately not table action merge.&lt;/P&gt;
&lt;P&gt;The available table actions append, update and deleteRows have a parameter whereTable that allows to base processing on values of another table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But even with using the whereTable parameter I couldn't find a way to define the append only for IDs in table B that don't already exist in table A and I couldn't think of a performant approach to work out the updates and inserts upfront.&lt;/P&gt;
&lt;P&gt;For this reason the approach I've chosen where I believe it should reasonably perform given the volumes of table B:&lt;/P&gt;
&lt;P&gt;1. Delete all rows in table A with an id that also exists in table B&lt;/P&gt;
&lt;P&gt;2. Append (insert) all rows from table B to table A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With databases a delete operation is much slower than an update or an insert. Not sure how that is with CAS - but then table B is not that big. I'm really curious how below code performs.&lt;/P&gt;
&lt;P&gt;If you're going to use this code with your real data then please let us know on how many nodes (threads) it executes and how long it takes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sessref=MySess;
%if %sysfunc(sessfound(&amp;amp;sessref)) %then
  %do;
    cas mySess terminate;
  %end;
cas &amp;amp;sessref cassessopts=(caslib="casuser");
libname casuser cas;

data casuser.A;
  input ID Name $ Height;
cards;
1 A 1
3 B 2
5 C 2
7 D 2
9 E 2
;
run;

data casuser.B (duplicate=yes);
  input ID Name $ Height;
cards;
2 A 2
4 B 3
5 C 4
7 D 5
;

proc cas;
  /* delete all rows in table A with an ID that also exists in table B */
  table.deleteRows /
    table={
      caslib='casuser'
      name='A',
      whereTable={
        caslib='casuser',
        name='B',
        vars={{name="ID"}}
        }
      };

  /* append (insert) all rows from table B to table A */
  table.append /
    source={caslib='casuser', name='B'},
    target={caslib='casuser', name='A'}
    ;

  /* drop table B */
  table.dropTable /
    caslib='casuser'
    ,name='B'
    ;
quit;
&lt;BR /&gt;proc print data=casuser.A;
run;

/*cas &amp;amp;sessref terminate;*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm creating table B with all rows on all nodes to avoid the need for data movement via cas_disk_cash during the delete and append operations. This is for performance reasons and given the volume of table B shouldn't impact memory consumption to much.&lt;/P&gt;
&lt;PRE&gt;data casuser.B (duplicate=yes);&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Not yet covered but something you need to address&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I don't save the cas in-memory table back to the physical table in the backing store and though this table gets out of sync.&lt;/P&gt;
&lt;P&gt;If you "lose" your CAS in-memory table for example as part of a CAS restart then you need somewhere the physical data for it. If this data doesn't already exist then you need also a process to upsert your physical table in the backing store.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Addendum&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;I was asking myself why you need to re-train your model every 20 minutes against all these 45M rows. But then that's not my home turf and when Googling I found that there appear to be cases where that's the right thing to do. ...but it's certainly worth for you to consider if there could be other ways to keep your model sufficiently up-to-date without having to re-process all the data every 20 minutes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 11:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-way-to-upsert-to-castable/m-p/916944#M361182</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-20T11:05:42Z</dc:date>
    </item>
  </channel>
</rss>

