sasdata-formats

Using a SAS format catalogue


I received a dataset and a format catalogue in SAS, and I am trying to get it to open, but somehow I am not correctly applying the format catalogue. Here is the code I've used. I have researched SAS sites and I thought I had the correct steps to call in the catalogue, but it's not working. I'm sure it's a basic error I'm making.

libname in 'U:/';
libname library 'U:/';

Options fmtsearch = (library.formats_raw); 

data ae;
set in.ae;
format 
    aeactae $AEMGMT.
    AEACTSM $ACTION.
    AEDVIS $VISIT.
    AEENDT DATE11.
    AEINT $AEINT.
    AEIRLOC $INJSITE.
    AEIRMEAS $YESNO.
    AEIRTERM $ISR.
    AEIRVIS $VISIT.
    AEIRYN $YESNO.
    AEOUT $OUTCOME.
    aerel $aerel.
    AESER $YESNO.
    AESTDT DATE11.
    AEYN $YESNO.
    EVTDT DATE11.
    LASTUPD EURDFDT20.;
run;

For each variable, I get the following error in the log:

format
            aeactae $AEMGMT.
                     --------               
ERROR 48-59: The format $AEMGMT was not found or could not be loaded.

Solution

  • Edit: Given the new information the answer changes. I leave the rest in case it's useful.

    You have a format dataset, not a format catalog. You need to run this:

    proc format cntlin=in.formats_raw;
    quit;
    

    to import the formats. This assumes it's created properly of course - it should have, at least, fmtname, start, label, and probably some other variables also (type, hlo, end are common).

    This imports formats saved to a SAS dataset to the work environment. If you want to create a permanent catalog, you should specify lib=in or wherever you want them stored on the proc format statement.


    Old answer:

    You're generally doing it right, though you're doing some things in ways you don't need to.

    library libname should be avoided. It's something people use who don't know how to use formats properly, but it really is not a good idea, because it gets special preference in format searching in a way that can be problematic if you have more than one. LIBRARY and WORK are automatically in the fmtsearch list and are given first priority unless explicitly listed. But that doesn't actually help you when the format catalog is not formats.sas7bcat anyway.

    In your case you should just define it once (in) and then do this:

    libname in 'U:/';
    Options fmtsearch = (in.formats_raw work);
    

    You put work in there to make sure your format catalog gets priority over it.

    Then it should work, if you have a file formats_raw.sas7bcat in that folder. If you don't, then you may have something else going on (you may have a file that's intended to be imported through cntlin if it is a .sas7bdat for example).

    This is a simple example of this working:

    libname temp 'c:\temp';
    proc format lib=temp.formats_raw;
      value YNF
      1='Yes'
      2='No'
      ;
    quit;
    
    options fmtsearch=(temp.formats_raw work);
    
    data test;
      x=1;
      format x YNF.;
      put x= ynf.;
    run;
    

    Change the fmtsearch to (temp work) and you'll see it fail (since temp\formats.sas7bcat does not exist).