BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

It shows correctly formatted in SAS Studio but fails to load in Visual Analytics. va1.png

 

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  -< 13   = "normal"
      LOW -< 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;
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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: https://go.documentation.sas.com/?docsetId=caldatamgmtcas&docsetTarget=n0jtz261h5qtg7n1j6ql02gd65lo....

 

Your Administrator needs to read all of it, particularly the topic "Persisting User-Defined Formats across Server Restarts"

 

Once this is in place you can use the following code. I deliberately used CAS actions, since this what the CAS server understands 

/*
 * 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="&casFmtLib";
  value class_age
    LOW -< 13 = "young n"
    13  -< 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="&casFmtLib" 
    name="&casFmtLib" replace=TRUE
  ;
  action sessionProp.promoteFmtLib / fmtLibName="&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;

 

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

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: https://go.documentation.sas.com/?docsetId=caldatamgmtcas&docsetTarget=n0jtz261h5qtg7n1j6ql02gd65lo....

 

Your Administrator needs to read all of it, particularly the topic "Persisting User-Defined Formats across Server Restarts"

 

Once this is in place you can use the following code. I deliberately used CAS actions, since this what the CAS server understands 

/*
 * 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="&casFmtLib";
  value class_age
    LOW -< 13 = "young n"
    13  -< 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="&casFmtLib" 
    name="&casFmtLib" replace=TRUE
  ;
  action sessionProp.promoteFmtLib / fmtLibName="&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;

 

acordes
Rhodochrosite | Level 12

Fantastic

 

Here comes the recipe that has brought success:

  1. in SAS Studio create a format catalogue as a lookup table
  2. save and promote the caslib format
  3. Go to Environment manager and assume super-role (done by admin) to create an empty format lib
  4. 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
  5. assign this format to the table you want to load to Visual Analytics
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;
acordes
Rhodochrosite | Level 12

Just one little downside.

Now I doesn't get the format applied in SAS Studio 🙂

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.

Do I have to make it visible via cas action?

 

bm.png