<?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: UDF in Visual Analytics in SAS Viya</title>
    <link>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685333#M671</link>
    <description>&lt;P&gt;Your SAS Viya Administrator has to define the proper search order for Format Libraries in SAS Environment Manager to make them available to any CAS session. More details here:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=caldatamgmtcas&amp;amp;docsetTarget=n0jtz261h5qtg7n1j6ql02gd65lo.htm&amp;amp;docsetVersion=3.5&amp;amp;locale=en#n1vzc092rf3pk8n1tj0t87jdaolf"&gt;https://go.documentation.sas.com/?docsetId=caldatamgmtcas&amp;amp;docsetTarget=n0jtz261h5qtg7n1j6ql02gd65lo.htm&amp;amp;docsetVersion=3.5&amp;amp;locale=en#n1vzc092rf3pk8n1tj0t87jdaolf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your Administrator needs to read all of it, particularly the topic "Persisting User-Defined Formats across Server Restarts"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once this is in place you can use the following code. I deliberately used CAS actions, since this what the CAS server understands&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
 * example code for creating user defined formats and use them
 * currently the search path must be set manualy in EVM 
 * 
 * NOTE: The search path for format libraries must be set by the 
 * SAS Viya administrator, so that we can use it
 *
 */
cas sugus sessopts=(caslib="public" metrics=true);

libname public cas caslib="public";

/*
 * show available format libraries
 * a format library does not have a 1:1 relationship with a CASlib
 * one CAS lib might contain several format libraries
 */
proc cas;
  action sessionProp.listFmtSearch;
  action sessionProp.listFmtLibs / showMemNames=TRUE showSource=TRUE;
  action table.fileinfo / caslib="formats";
  run;
quit;

/*
 * create a format
 * the format will be created at both locations
 * SAS: work.formats
 * CAS: in the named CAS format library (CAS table)
 *      please note, it has a session scope
 */
%let casFmtLib = myFmtLib;

proc format sessref=sugus casfmtlib="&amp;amp;casFmtLib";
  value class_age
    LOW -&amp;lt; 13 = "young n"
    13  -&amp;lt; 14 = "normal n"
    14  -  HIGH = "old n"
  ;
run;

/*
 * save the format defintion to a CAS library in sashdat format
 * still have a session scope format lib
 * do then need to promote it
 */
proc cas;
  action sessionProp.saveFmtLib /
    caslib="formats" fmtLibName="&amp;amp;casFmtLib" 
    name="&amp;amp;casFmtLib" replace=TRUE
  ;
  action sessionProp.promoteFmtLib / fmtLibName="&amp;amp;casFmtLib" replace=true;
  action sessionProp.listFmtSearch;
  action sessionProp.listFmtLibs / showMemNames=TRUE showSource=TRUE;
  run;
quit;

/*
 * create the data
 */
proc delete data=public.class_format_test;
run;

data public.class_format_test(promote=yes);
  set sashelp.class;
  ageGroup = age;
  format ageGroup class_age.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Sep 2020 08:19:07 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2020-09-21T08:19:07Z</dc:date>
    <item>
      <title>UDF in Visual Analytics</title>
      <link>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685119#M669</link>
      <description>&lt;P&gt;It shows correctly formatted in SAS Studio but fails to load in Visual Analytics. &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="va1.png" style="width: 631px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49552i87D511C64D83F19B/image-size/large?v=v2&amp;amp;px=999" role="button" title="va1.png" alt="va1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cas sugus sessopts=(caslib=casuser timeout=1800 locale="en_US");
cas sugus sessopts=(caslib="casuser");
cas sugus listformats scope=global members;

options nofmterr;

cas sugus dropfmtlib fmtlibname=myFmtLib  /* 2 */
fmtsearchremove;

proc format sessref=sugus casfmtlib="myFmtLib";  /* 4 */
   value class_age
      13  -  HIGH = "old"
      12  -&amp;lt; 13   = "normal"
      LOW -&amp;lt; 12   = "young";
run;


proc delete data=public.class_format_test;
run;

data public.class_format_test(promote=yes);
  set sashelp.class;
  ageGroup = age;
  format ageGroup class_age.;
run;


cas sugus savefmtlib fmtlibname=myFmtLib         /* 5 */
   table="myFmtLib.sashdat" caslib=public replace;

cas sugus addfmtlib fmtlibname=myFmtLib     /* 2 */
   table="myFmtLib.sashdat" caslib=public replacefmtlib;

cas sugus promotefmtlib fmtlibname=myFmtLib replace;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2020 21:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685119#M669</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2020-09-18T21:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: UDF in Visual Analytics</title>
      <link>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685333#M671</link>
      <description>&lt;P&gt;Your SAS Viya Administrator has to define the proper search order for Format Libraries in SAS Environment Manager to make them available to any CAS session. More details here:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=caldatamgmtcas&amp;amp;docsetTarget=n0jtz261h5qtg7n1j6ql02gd65lo.htm&amp;amp;docsetVersion=3.5&amp;amp;locale=en#n1vzc092rf3pk8n1tj0t87jdaolf"&gt;https://go.documentation.sas.com/?docsetId=caldatamgmtcas&amp;amp;docsetTarget=n0jtz261h5qtg7n1j6ql02gd65lo.htm&amp;amp;docsetVersion=3.5&amp;amp;locale=en#n1vzc092rf3pk8n1tj0t87jdaolf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your Administrator needs to read all of it, particularly the topic "Persisting User-Defined Formats across Server Restarts"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once this is in place you can use the following code. I deliberately used CAS actions, since this what the CAS server understands&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
 * example code for creating user defined formats and use them
 * currently the search path must be set manualy in EVM 
 * 
 * NOTE: The search path for format libraries must be set by the 
 * SAS Viya administrator, so that we can use it
 *
 */
cas sugus sessopts=(caslib="public" metrics=true);

libname public cas caslib="public";

/*
 * show available format libraries
 * a format library does not have a 1:1 relationship with a CASlib
 * one CAS lib might contain several format libraries
 */
proc cas;
  action sessionProp.listFmtSearch;
  action sessionProp.listFmtLibs / showMemNames=TRUE showSource=TRUE;
  action table.fileinfo / caslib="formats";
  run;
quit;

/*
 * create a format
 * the format will be created at both locations
 * SAS: work.formats
 * CAS: in the named CAS format library (CAS table)
 *      please note, it has a session scope
 */
%let casFmtLib = myFmtLib;

proc format sessref=sugus casfmtlib="&amp;amp;casFmtLib";
  value class_age
    LOW -&amp;lt; 13 = "young n"
    13  -&amp;lt; 14 = "normal n"
    14  -  HIGH = "old n"
  ;
run;

/*
 * save the format defintion to a CAS library in sashdat format
 * still have a session scope format lib
 * do then need to promote it
 */
proc cas;
  action sessionProp.saveFmtLib /
    caslib="formats" fmtLibName="&amp;amp;casFmtLib" 
    name="&amp;amp;casFmtLib" replace=TRUE
  ;
  action sessionProp.promoteFmtLib / fmtLibName="&amp;amp;casFmtLib" replace=true;
  action sessionProp.listFmtSearch;
  action sessionProp.listFmtLibs / showMemNames=TRUE showSource=TRUE;
  run;
quit;

/*
 * create the data
 */
proc delete data=public.class_format_test;
run;

data public.class_format_test(promote=yes);
  set sashelp.class;
  ageGroup = age;
  format ageGroup class_age.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 08:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685333#M671</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-09-21T08:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: UDF in Visual Analytics</title>
      <link>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685346#M672</link>
      <description>&lt;P&gt;Fantastic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here comes the recipe that has brought success:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;in SAS Studio create a format catalogue as a lookup table&lt;/LI&gt;
&lt;LI&gt;save and promote the caslib format&lt;/LI&gt;
&lt;LI&gt;Go to Environment manager and assume super-role (done by admin) to create an empty format lib&lt;/LI&gt;
&lt;LI&gt;choose in Environment Manager's UDF page the format that was created in SAS Studio and copy it to the newly created empty format lib&lt;/LI&gt;
&lt;LI&gt;assign this format to the table you want to load to Visual Analytics&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fmt;
   set FORMATIN(rename=(gr_vr=start LITERAL=label)) end=eof;
   retain fmtname "brand" type "c";
   output;
   if eof then do;
      start=""; Label="";
      HLO="O"; output;
   end;
run;
 
proc format library=work cntlin=fmt casfmtlib="myFmtLib";
run;

cas mysession savefmtlib fmtlibname=myFmtLib         /* 5 */
   table="myFmtLib.sashdat" caslib=casuser replace;

cas mysession addfmtlib fmtlibname=myFmtLib     /* 2 */
   table="myFmtLib.sashdat" caslib=casuser replacefmtlib;

cas mysession promotefmtlib fmtlibname=myFmtLib replace;

/*Go to Environment Manager. When I make the copy of the brand format I rename it to GRVR_LIT*/

proc delete data=public.test_udf;
run;

data public.test_udf(promote=yes);
set RISKNOBA.TMAIMG_GRVR_MATCH;
FORMAT LITERAL $GRVR_LIT.;
LITERAL=GR_VR;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Sep 2020 09:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685346#M672</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2020-09-21T09:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: UDF in Visual Analytics</title>
      <link>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685350#M673</link>
      <description>&lt;P&gt;Just one little downside.&lt;/P&gt;
&lt;P&gt;Now I doesn't get the format applied in SAS Studio &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;when mapped to its code-wis created format $brand in MYFMTLIB it's ok, but its copied version $grvr_lit in admin-side created lib BUSINESS_MAPPER works for Visual Analytics but not for SAS Studio.&lt;/P&gt;
&lt;P&gt;Do I have to make it visible via cas action?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bm.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49589iD2B04BF3E3AD9377/image-size/large?v=v2&amp;amp;px=999" role="button" title="bm.png" alt="bm.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 09:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/UDF-in-Visual-Analytics/m-p/685350#M673</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2020-09-21T09:31:29Z</dc:date>
    </item>
  </channel>
</rss>

