<?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: applying user-defined format to cas in-memory data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762614#M241475</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="transcript"&gt;
&lt;P&gt;After a table is in memory, you can't assign formats to its columns. So, for procedures that run on the CAS server, you use a FORMAT statement with the CASUTIL procedure to assign a format to a column before the table is loaded into memory.&lt;/P&gt;
&lt;DIV id="tinyMceEditorsbxkoenk_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;PRE&gt;proc casutil;
    &lt;SPAN class="hilight"&gt;format OrderType typefmt.;&lt;/SPAN&gt;                                     
    &lt;SPAN class="hilight"&gt;load data=pvbase.orders casout="orders"&lt;/SPAN&gt; 
         &lt;SPAN class="hilight"&gt;outcaslib='casuser' replace;&lt;/SPAN&gt;
    contents casdata="orders";
quit;

proc freqtab data=casuser.orders;
    tables OrderType;
run;&lt;/PRE&gt;
&lt;P&gt;Here we use a FORMAT statement in PROC CASUTIL to apply the TYPEFMT format to the OrderType column, and then we load pvbase.orders into an in-memory table named orders in the Casuser caslib. The REPLACE option overwrites the orders table if one exists. The PROC FREQTAB step analyzes the formatted values of OrderType, reporting on the three types of orders: In-store, Shipped, and Curbside.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Saving and Reading CAS Format Libraries!&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV id="transcript"&gt;
&lt;P&gt;Similar to formats in Base SAS, CAS formats exist only for the duration of the CAS session. So how can you save formats so that they're available in future CAS sessions?&lt;BR /&gt;Let me know if you want info on the latter question as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Thu, 19 Aug 2021 17:40:54 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-08-19T17:40:54Z</dc:date>
    <item>
      <title>applying user-defined format to cas in-memory data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762538#M241453</link>
      <description>&lt;P&gt;I have a user-defined format that I want to apply to CAS in-memory data.&amp;nbsp; I've defined the format as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format casfmtlib="casformat";&lt;BR /&gt;&amp;nbsp; picture ymdhms other='%0Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run that, the log shows:&lt;/P&gt;&lt;DIV class="sasSource"&gt;80 proc format casfmtlib="casformat";&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Both CAS based formats and catalog-based formats will be written. The CAS based formats will be written to the session&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;MCCOFFERSESS.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;81 picture ymdhms other='%0Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Format library CASFORMAT added. Format search update using parameter APPEND completed.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Format YMDHMS has been output.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;When I subsequently try to apply the format in a proc cas block, I get a Warning in the log:&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;"&lt;SPAN&gt;WARNING: The function failed to execute."&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;SPAN&gt;I'm trying to apply the format using then "putn" function:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;SPAN&gt;print putn(start_date, 'ymdhms.');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;SPAN&gt;Any advice would be greatly appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;SPAN&gt;The full proc cas step is:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;P&gt;proc cas;&lt;BR /&gt;&amp;nbsp; table.fileInfo status=rc result=info /&lt;BR /&gt;&amp;nbsp; &amp;nbsp; caslib="my_cas"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; , path="my_log_link_visit_action.sashdat"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; , rowcount=true&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (info.FileInfo[1,5] &amp;gt; 0) then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; table.loadTable status=rc result=r /&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; caslib="my_cas"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; , path="my_log_link_visit_action.sashdat"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; , casout={&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; caslib="my_cas"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , name="my_log_link_visit_action"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , replace=true&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;if (rc.severity = 0) then do;&lt;BR /&gt;&amp;nbsp; simple.summary result=daterange /&lt;BR /&gt;&amp;nbsp; table={&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; caslib="my_cas"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , name="my_log_link_visit_action"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp;, inputs={&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {name="server_time"}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp;, subSet={"MAX"}&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;start_date = daterange.Summary[1,2];&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if (intck('dtday', daterange.Summary[1,2], datetime()) &amp;gt; 30) then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date = intnx('dtday', daterange.Summary[1,2], 30);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else end_date = datetime();&lt;BR /&gt;print '&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; ' putn(start_date, 'YMDHMS.');&lt;BR /&gt;print '&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; ' end_date;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 19 Aug 2021 13:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762538#M241453</guid>
      <dc:creator>jimleone</dc:creator>
      <dc:date>2021-08-19T13:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: applying user-defined format to cas in-memory data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762614#M241475</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="transcript"&gt;
&lt;P&gt;After a table is in memory, you can't assign formats to its columns. So, for procedures that run on the CAS server, you use a FORMAT statement with the CASUTIL procedure to assign a format to a column before the table is loaded into memory.&lt;/P&gt;
&lt;DIV id="tinyMceEditorsbxkoenk_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;PRE&gt;proc casutil;
    &lt;SPAN class="hilight"&gt;format OrderType typefmt.;&lt;/SPAN&gt;                                     
    &lt;SPAN class="hilight"&gt;load data=pvbase.orders casout="orders"&lt;/SPAN&gt; 
         &lt;SPAN class="hilight"&gt;outcaslib='casuser' replace;&lt;/SPAN&gt;
    contents casdata="orders";
quit;

proc freqtab data=casuser.orders;
    tables OrderType;
run;&lt;/PRE&gt;
&lt;P&gt;Here we use a FORMAT statement in PROC CASUTIL to apply the TYPEFMT format to the OrderType column, and then we load pvbase.orders into an in-memory table named orders in the Casuser caslib. The REPLACE option overwrites the orders table if one exists. The PROC FREQTAB step analyzes the formatted values of OrderType, reporting on the three types of orders: In-store, Shipped, and Curbside.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Saving and Reading CAS Format Libraries!&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV id="transcript"&gt;
&lt;P&gt;Similar to formats in Base SAS, CAS formats exist only for the duration of the CAS session. So how can you save formats so that they're available in future CAS sessions?&lt;BR /&gt;Let me know if you want info on the latter question as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 19 Aug 2021 17:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762614#M241475</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-19T17:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: applying user-defined format to cas in-memory data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762620#M241478</link>
      <description>&lt;P&gt;Thanks, Koen.&amp;nbsp; I just made this discovery and I appreciate your confirmation and detailed explanation.&amp;nbsp; I would like to point out, though, that the documentation does not deliver this information as explicitly as you did.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read this doc yesterday:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/pgmdiff/n0k0n33nje512xn1cl49573ei8k0.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/pgmdiff/n0k0n33nje512xn1cl49573ei8k0.htm&lt;/A&gt;.&amp;nbsp; This page states: "&lt;SPAN&gt;It is a best practice to assign a format to a variable before the table is loaded into the server.", which is not quite as explicit as your comment, which to me could be read as "you can't do that."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Anyway...solved!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 17:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762620#M241478</guid>
      <dc:creator>jimleone</dc:creator>
      <dc:date>2021-08-19T17:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: applying user-defined format to cas in-memory data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762624#M241480</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391588"&gt;@jimleone&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My information comes from a SAS VIYA 3.5 programming course.&lt;/P&gt;
&lt;P&gt;I always do it that way (because I looked at that course in October 2020).&lt;/P&gt;
&lt;P&gt;Maybe it changed in VIYA 4 (?), but the doc you mention is SAS VIYA 3.5 so I think this doc should be more explicit indeed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 18:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/762624#M241480</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-19T18:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: applying user-defined format to cas in-memory data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/863408#M341068</link>
      <description>&lt;P&gt;You can apply a format to table in memory using ALTERTABLE - here I'm loading an Oracle table into memory, and then altering the format for one column&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc casutil ; 
   load incaslib="oracle" casdata="CARS" outcaslib="CASUSER" casout="CARS" replace ; 
   altertable incaslib="casuser" casdata="CARS"  
      columns = { {name= "Cylinders" format="roman." } } ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The solution provide previously, works well when loading a table from a Library (DATE=...), but will not work when loading from a CAS Library (INCASELIB=...), such as the Oracle example above.&lt;/P&gt;
&lt;P&gt;Using ALTERTABLE should work for any in memory table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="cs746A5FAB"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 11:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/applying-user-defined-format-to-cas-in-memory-data/m-p/863408#M341068</guid>
      <dc:creator>MarkDawson</dc:creator>
      <dc:date>2023-03-10T11:52:26Z</dc:date>
    </item>
  </channel>
</rss>

