04-12-2015 09:30 PM
Like the title says, I have a format library for variables' values but now have to re-apply the formats on the data every time using SAS (or restarting, to be more exact).
I wonder if there's some way to apply the formats permanently on the data, so that we don't have to worry about that additional steps. For example, when sharing data, I don't really want to include both the data file and the format library in the package, but rather prefer to make it as compact as possible.
I also encounter this problem: After applying formats for the data set in WORK library, I save it as a permanent data set. At that time, the saving process works fine, the output data works fine, other things are fine.
So I close SAS and don't save the format library. When I reopen SAS, I fail to load the permanent data set, i.e., it comes to a blank table (although the file size is still ~100MB!). The log message is that "ERROR: Format ZFormat not found or couldn't be loaded for variable Z."
04-12-2015 10:40 PM
Store your formats in your SASUSER library with option LIB=SASUSER in the proc format statement and your formats will be stored in the FORMATS catalog of your SASUSER library. The SASUSER library is permanent which means that your format definitions will persist to future SAS sessions.
04-12-2015 11:49 PM
Thanks for the advice. I did that and was able to create a format catalog within SASUSER. Some follow-up questions:
1. When I reload the permanent SAS file, it doesn't automatically "synchronize" with the format catalog in SASUSER. Does it mean I still need to apply formats on variables (e.g., like this: DATA HAVE; SET HAVE; FORMAT Var1 Var1Fmt. ? Is there some statement for the permanent data file to recognize the format catalog and align its variables with the defined formats?
2. It seems like a separate format file is still needed when sharing data, isn't it?
04-13-2015 12:37 AM
If you want to share your permanent formats with other users then a better option is to store your formats in the SAS library called LIBRARY. If you use LIB = LIBRARY on your PROC FORMAT statement then your format will be stored the FORMATS catalog in LIBRARY. All users automatically have the LIBRARY library allocated and SAS searches this location for formats.
04-13-2015 04:25 AM
The others are answering your question with regards to format catalog. My opinion on the matter however is to avoid format catalogs. These are proprietary. I would do one of two things.
- Have the code and full text in separate columns, i.e. code=variable, decode=put(variable,format), and have no formats applied to the variables.
- Have the code with formats applied, and have a lookup table, e.g:
create table FULL as
from HAVE A
left join CODE_LIST B
Don't know what its like elsewhere but in my area XML is coming in a big way, i.e. text based, non-proprietary.
04-13-2015 05:11 AM
Avoid storing formats in the SASUSER and the LIBRARY namings.
- SASUSER is personally and only open at the DMS (local desktop) in a single user approach.
All modern EGUIDE SAS-Studio (EIP) are using some of app-server approaches (WS one of those) at the best setting it as read-only. Blocking any updaets/writes
- LIBRARY is the old name for all kind of executables (STEPLIB JOBLIB) being accessible. It still is functioning that way. Avoid conflict with that.
Where to store formats for your dataset?
- As long as they are belonging to that dataset you can store them in the same libname of the dataset. That is why the library option with proc format is there
- Activating those formats in that library is needing to adjust the fmtsearch option
SAS(R) 9.4 System Options: Reference, Third Edition You see the library option still there in the search order as default after work.
Setting the option wiht nofmterr is allowing you to access the data without errors without formats.
In a more bigger organization you could get into the need for some release management on sas-formats having their own life-cycle.
04-19-2015 10:59 PM
What does the dataset look like when you import back from SPSS? Are the value labels in new character columns or are the numeric variables transformed into character?
07-29-2015 07:55 AM
The data imported from SPSS looks just fine, i.e., numeric values aren't transformed to characters. Yet it also creates a format library. So I'd take back the previous words, the problem I tried to tackle remains.
07-29-2015 11:11 AM
Anything involving formats tends to involve two pieces (IMHO) 1) where to store and 2) accessing.
The first is a format catalog in a permanent library. If multiple users need to use this transparently then that means a library everyone has at least read privileges to. (In a shared environment I would strongly recommend a limited number of users with write or delete privileges.)
Then every user has to have that library in their format search path. If using a server version I have to believe that can't be that difficult. If you aren't in a server environment or have a mixture then having an autoexec or similar program run at start with:
options Append(fmtsearch= (name(s) of libraries to search for formats)); (or INSERT)
which will add those libraries to the end of any currently assigned libraries to look for formats.
Warning: The format search path is an ordered list. If you have format. in multiple libraries then the first library encountered version will be used.
07-29-2015 08:28 PM
Another angle that you might want to consider:
This statement lets you work with the data set even if the formats are not available. Any formats that can't be found will automatically be converted to simple formats such as 8. or $8. So this won't get you the formatted values, but it will let you work with the data if the format library is unavailable.