It shows correctly formatted in SAS Studio but fails to load in Visual Analytics.
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;
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;
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;
Fantastic
Here comes the recipe that has brought success:
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;
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?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.