<?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: Interacting with results of CAS actions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859427#M339551</link>
    <description>Thank you. The paper looks promising.&lt;BR /&gt;Hopefully this will help me sort out how to loop through the different by group tables and save them to different result tables.</description>
    <pubDate>Fri, 17 Feb 2023 19:08:09 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2023-02-17T19:08:09Z</dc:date>
    <item>
      <title>Interacting with results of CAS actions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859340#M339529</link>
      <description>&lt;P&gt;I'm lost.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that I can achieve the same with a oldie-but-goldie proc summary followed by a proc transpose or its siblings in cas actions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I want to achieve it with the result, findtable and saveresult combinatuion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried without success 2 different approaches.&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;To loop through the bygroup results and save them into work.summary_1, work.summary_2 using the loop counter i&lt;/LI&gt;
&lt;LI&gt;to save to the same work.summary and append the results using datastep.runcode&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I don't know how to create a macro variable inside the loop, it gets quoted and secondly it does not recognize the loop counter i.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the datastep.runcode fails IMO because of the fact that it does not allow a set statement for the work directory being the only library that saveresult admits....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data casuser.cars;
set sashelp.cars;
run;

cas mySession sessopts=(caslib="casuser"); 
proc cas;
   session mysession;
   simple.mdSummary result=res status=s /             
      inputs={"Horsepower", "Invoice", "Length" },                        
      subSet={ "mean",  "N"},
      sets={{groupBy={"Make"}},                   
         {groupBy={"make", "type"} }},
      table={ name="cars"};
run;
describe res;

print res["ByGroupSet2.ByGroup1.MDSummary"]; 

do i=1 to 2;
s=res[cats("ByGroupSet2.ByGroup",i, ".MDSummary")];
%let savename=%sysfunc(cats('summary_', i));
saveresult s dataout=work.summary;

/* source originTables; */
/*         data risk.all_sum; */
/*         set work.summary risk.all_sum; */
/*         run; */
/* endsource; */
/* dataStep.runCode / code=originTables; */

end;

/* print res["ByGroupSet2.MDSummary", 3:5]; */
/* do i = 1 to res.MDSummary.nrows; */
/* print res["MDSummary"][2, {1 3} ]; */
/* end; */
 
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 10:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859340#M339529</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-02-17T10:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Interacting with results of CAS actions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859373#M339540</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following statements may help. &amp;nbsp; Actually, consider them as two separate blocks / alternatives.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. You actually solved part of the problem by specifying the table object key (MDSummary) , therefore don't need to use findable in block 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. In block 2 , &amp;nbsp;you can use findtable (your initial results object) to programmatically identify the table. &amp;nbsp;This is useful when you are unsure as to what your object really calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;print res["ByGroupSet2.ByGroup1.MDSummary"]; 

resobject=res["ByGroupSet2.ByGroup1.MDSummary"]; 

saveresult resobject dataout=work.abc;


/* Block 2 */
/* If you want to use findable */

resobject2 = findtable(res);

saveresult resobject dataout=work.xyz;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to quickly touch upon another aspect - in your do loop (whenever / if you want to use a do loop), the dim(result) statement will identify the upper limit (perhaps you know that already, my apologies). &amp;nbsp; Just for interest, an alternative approach (perhaps less well-known or used) is provided in&amp;nbsp;&lt;A title="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3177-2019.pdf" href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3177-2019.pdf" target="_blank"&gt;this paper&lt;/A&gt;. &amp;nbsp;Essentially the concept is that you create a new column in the result object, which actually is the result of a function you can define (to operate on each line of the result object). &amp;nbsp; Search for WHERE and COMPUTE operator in the link. &amp;nbsp;I like it for its conciseness. &amp;nbsp;However, this may be a little new for those who are used to the established SAS / CASL ways of programming. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 13:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859373#M339540</guid>
      <dc:creator>Sundaresh1</dc:creator>
      <dc:date>2023-02-17T13:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Interacting with results of CAS actions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859427#M339551</link>
      <description>Thank you. The paper looks promising.&lt;BR /&gt;Hopefully this will help me sort out how to loop through the different by group tables and save them to different result tables.</description>
      <pubDate>Fri, 17 Feb 2023 19:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859427#M339551</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-02-17T19:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Interacting with results of CAS actions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859681#M339627</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt; within the proc cas block I'm not able to save all different by-groups&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;or to different summary tables using the savestate line because I do not succeed in creating a different target table name within the do-loop&lt;/LI&gt;
&lt;LI&gt;or to use a datastep.runcode appending / setting the different by-group related versions of the the summary table (cas in this case)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Furthermore I've noticed that&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;saveresult s dataout=work.summary;&lt;/PRE&gt;
&lt;P&gt;and&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;saveresult s casout="summary" caslib="risk";&lt;/PRE&gt;
&lt;P&gt;produce different output tables. the cas tables lacks the grouping variables ???&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Consolas; font-size: 9.75pt; color: #8e8e8e;" lang="es"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 09:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859681#M339627</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-02-20T09:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Interacting with results of CAS actions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859713#M339636</link>
      <description>&lt;P&gt;To combine the individual result tables you can use the CASL function COMBINE_TABLES.&lt;/P&gt;
&lt;P&gt;You can use the SAVERESULTS statement to write to a CAS table, this allows for a dynamic name, this is not possible for a SAS data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cas sugus sessopts=(caslib="casuser");
libname casuser cas caslib="casuser";

data casuser.cars;
  set sashelp.cars;
run;

proc cas;
  action simple.mdSummary result=res status=s /             
    inputs={"Horsepower", "Invoice", "Length" },                        
    subSet={ "mean",  "N"},
    sets={
    	{groupBy={"origin"}} 
      {groupBy={"origin", "type"} }
    },
    table={ name="cars"}
  ;
run;
describe res;
run;
do i=1 to 2;
  s=combine_tables(res, cats("ByGroupSet", i));
  table = cats("summary_a", i);
  saveresult s casout=table caslib="casuser" replace;
end;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Feb 2023 14:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interacting-with-results-of-CAS-actions/m-p/859713#M339636</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2023-02-20T14:19:21Z</dc:date>
    </item>
  </channel>
</rss>

