BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14
Hello
Let's say that someone send me a data set that is saved in a permanent library.
Let's say that I run proc sql on that data set and there is a field with user defined format .
Is it possible to find out what is the full definition of this user defined format ?
Please note that it might happen that some of the format values in proc format are not in the data set but I still want to know what is the full definition of this proc format ?
( in a case that the person who create this user defined format is not available and cannot as him )
7 REPLIES 7
SASKiwi
PROC Star

Only if they either sent you the code for creating the user-defined format or the SAS catalog containing it. You can use the SAS catalog to reverse engineer the code that created the format.

 

Just be clear that SAS datasets do not store SAS format definitions.

Ronein
Meteorite | Level 14
Let's say that the guy who created the data set didn't sebd me the code of user defined format.
How can I check if the catalog containing it?
May you please show code for it?
SASKiwi
PROC Star

You can use PROC FORMAT to check if there are formats in a SAS catalog:

proc format library = MyLib.MyCatalog FMTLIB;
run;

Here is another example from the documentation.

Reeza
Super User

If you think the library has formats (I'd bet against it if related to your previous question) you can use the following to have all formats outputed to a SAS data set with their defintions. If you're not familiar with CNTLIN/CNTLOUT data sets you may to read up on formats. 


Change demo to the permanent library where the file is stored to check if the format exists.

 

proc format library=demo cntlout=check;
run;

@Ronein wrote:
Let's say that the guy who created the data set didn't sebd me the code of user defined format.
How can I check if the catalog containing it?
May you please show code for it?

*create a libname reference;
libname demo '/home/fkhurshed/Demo1';

*create a format in the library;
proc format library=demo;
value age_fmt 
0 - 9 = 'Child'
10-12 = 'Pre-Teen'
13-19 = 'Teenager'
19-high = 'Adult';
run;

*Tell SAS to use this library for formats;
OPTIONS FMTSEARCH = ( demo );

*check that it works;
proc print data=sashelp.class;
format age age_fmt.;
run;

*output the format back to a dataset called check;
proc format library=demo cntlout=check;
run;

*print out format definition ;
proc print data=check;run;

Kurt_Bremser
Super User

To get a working version of a format, you need either

  • PROC FORMAT code to create the format
  • a CNTLIN dataset for PROC FORMAT
  • a catalog containing the format
  • a logical description of the format, so you can create the code yourself

Without neither, you're hosed and have to resort to guessing.

 

The options are listed in order of being useful; code works everywhere, while catalogs and datasets may have issues with your platform.

Tom
Super User Tom
Super User

Datasets live in files with SAS7BDAT extension.  Formats live in catalogs.  Catalogs live in files with SAS7BCAT extension.  If they sent you a catalog file then you can check if the format is in that catalog by using PROC FORMAT.

 

Point a libref at the directory that contains the catalog.  Then use the libref you created and the name of the catalog file with PROC FORMAT.  So if the file is named 'mycat.sas7bcat' then the code might look like this.

libname mylib 'some directory';
proc format lib=mylib.mycat cntlout=formats;
run;
proc freq data=formats;
   tables fmtname*fmttype / list;
run;

Note that catalogs are not readable across versions of SAS (or version of the operating system).  So if they made the catalog in an earlier version of SAS or used a different operating system then you cannot read the file.

 

If you really want them to send you the definition they need to either use PROC CPORT to make a transportable version of the catalog.  Or use the code above to make a dataset with the format definitions and send that dataset.  Or just send the SAS statments to define the format(s).

AllanBowe
Barite | Level 11

This macro will export all the format definitions for a particular dataset, so long as they are contained in the FMTSEARCH path:  https://core.sasjs.io/mp__getformats_8sas.html

 

Usage:

%mp_getformats(
  lib=YOURLIB
  ,ds=YOURDATASET
  ,outsummary=work.summarytable
  ,outdetail=work.formatdetails
)
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1567 views
  • 3 likes
  • 6 in conversation