Saving work.formats to a permanent location

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Saving work.formats to a permanent location

I am currently attempting to save formats that were read in using proc import from a SPSS .sav file

 

I read the data into a work. library as a temporary dataset. How do I then save these formats for future use in SAS datasets. 


Accepted Solutions
Solution
‎01-01-2017 04:08 PM
Super User
Posts: 3,237

Re: Saving work.formats to a permanent location

[ Edited ]

The easiest method for storing your user-defined SAS formats is to use PROC CATALOG to copy them to the permanent location then use FMTSEARCH to point to PERM:

 

proc catalog catalog = temp.formats;
  copy out = perm.formats;
  run;
quit;

options fmtsearch = (work, library, perm);

 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,479

Re: Saving work.formats to a permanent location

[ Edited ]

Assume you creadted work.spss_formats as sas dataset.

I don't know SPSS therefore I don't know what variables you have in that dataset.

 

Anyhow you can use:

proc format lib=anylib cntlin=work.spss_formats; run;

You may need rename variables and add format name variable, before running the proc format.

 

Does your spss_formats hold data for one format or more than one ?

 

Please post a sample of your spss_formats daraset.

Occasional Contributor
Posts: 7

Re: Saving work.formats to a permanent location

The spss formats are created and placed into a work.formats catalog when the data is imported using proc import.

 

ROC IMPORT OUT= WORK.cluster0
DATAFILE= "C:\Users\micha\Dropbox\1. Dissertation\Paper 2\Data\ACHA-NCHA FALL 2015 REFERENCE GROUP-1R BLIND-SAWDEY.sav"
DBMS=SPSS REPLACE;RUN;

 

I then continued to use the work folder as in this program, there is quite a bit of recoding and checking of recodes happening. Later on in the program, I needed to then take the recoded data set and save it as a permanent to be used at a later time for merging it back with data that we conducted a latent class analysis with in mplus. 

 

The problem that arises, is, even when saving the data to a permanent dataset, the formats folder is a temp.formats. This is what I cannot overcome 

Super User
Posts: 19,167

Re: Saving work.formats to a permanent location

Save the dataset to a permanent library. If you're using SAS UE see the Analytics U forum for many questions on how to save to a permanent library.  

Occasional Contributor
Posts: 7

Re: Saving work.formats to a permanent location

This is actually exactly what I attempted to do. I needed to data to be saved after recoding so it could be re-merged with data from a secondary analysis that had the same identifier variable.

 

The creation of the permanent dataset did not pull the formats over from work.formats. Upon closing out of SAS and then reopening a new SAS program and attempting to call the data, I get errors that the formats were not found or loaded. This is because SAS is holding the original formats from the other program as temp.formats. 

SAS Super FREQ
Posts: 8,820

Re: Saving work.formats to a permanent location

Hi:
Please read this Tech Support note: http://support.sas.com/kb/23/007.html -- to save your formats from one session to another, you will have to follow the steps outlined in this note.

Or look at this paper and some of the examples at the end: http://support.sas.com/resources/papers/proceedings12/048-2012.pdf

Or, this documentation topic: http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1lxb8tukmkz70n1xakol... that shows how to use a permanent format.

cynthia
Occasional Contributor
Posts: 7

Re: Saving work.formats to a permanent location

[ Edited ]

Hi Cynthia,

 

I have been through both of these to no avail. The resulting libname.format is empty and the original work.formats is still a temp.

 

The code I was trying was (Ive tried different variations, but this is what I keep coming back to):

 

libname Perm "C: location";

data Perm.original_data; set work.data;  */ creating the permanent data set/*;

 

Proc FORMAT library= Perm.original_data;

OPTIONS FMTSEARCH= (work.formats);

run;

 

What am I missing?

Super User
Posts: 19,167

Re: Saving work.formats to a permanent location

You have a catalog and a dataset or a catalog? 

You can use CNTLOUT to generate a dataset instead of a catalog. 

 

What does you log say regardimg your code? Your using the appropriate method, but we don't know how,it's 'not working'. 

Occasional Contributor
Posts: 7

Re: Saving work.formats to a permanent location

[ Edited ]

The dataset and work.formats (catalog) are together. I want to move the catalog to be able to use it from step 7 and on below.

 

I believe you are saying that the CNTLOUT will create a dataset with the formats permanantly attached? If so, this would work. 

 

So from start the finish:

1. Import dataset using proc import from SPSS file into work.datafile (creates data set and work.formats)

2. Recoding and Data management using work.datafile(s)

3. Libname for permanent file (libname)

4. Create permanant file (data libname.datafile; set work.datafile)

5. Proc format code listed above. Using OPTIONS FMTSEARCH

6. Close this program and SAS

7. Run my other analysis in mplus.

8. Open SAS back up and Merge data back from other analysis, import all data

9. Merge with with libname.datafile. Get format error for every variable (All 200+) (e.g. ERROR: The format NQ1A was not found or could not be loaded.)

Solution
‎01-01-2017 04:08 PM
Super User
Posts: 3,237

Re: Saving work.formats to a permanent location

[ Edited ]

The easiest method for storing your user-defined SAS formats is to use PROC CATALOG to copy them to the permanent location then use FMTSEARCH to point to PERM:

 

proc catalog catalog = temp.formats;
  copy out = perm.formats;
  run;
quit;

options fmtsearch = (work, library, perm);

 

Super User
Posts: 19,167

Re: Saving work.formats to a permanent location

CNTLOUT creates a dataset with formats defined that you can save to a permanent dataset. It does not permanently attach the formats. This dataset is then used in new programs to create/use formats. 

 

Proc format cntlout=Perm.MyFormats;

run;

 

Now, in new session with perm library assigned

 

proc format cntin=MyFormats;

run;

 

*rest of programs go here;

Occasional Contributor
Posts: 7

Re: Saving work.formats to a permanent location

THIS WORKED

 

I allowed me to move the catalog. Then, when opening the second program where I plan to do my analysis I called the libname and did an OPTIONS FTMSEARCH (libname.formats).

 

Thank you very MUCH

SAS Super FREQ
Posts: 8,820

Re: Saving work.formats to a permanent location

[ Edited ]

Hi:
I do not believe you are following the model correctly. For example, what is in WORK.DATA? You are using it to create PERM.ORIGINAL_DATA? Does WORK.DATA contain the information you want to turn into a format?

Second, you are telling PROC FORMAT the the format library is PERM.ORIGINAL_DATA -- typically, you do not specify a dataset as a library location for the format catalog. Next, you specify a FMTSEARCH option for WORK.FORMATS. This is odd because you just tried to create a PERM location as a format catalog.

So I don't think you quite have down yet what needs to happen in what order. Typically you define and create your format catalog FIRST and then you test it and see whether the formats work and finally you re-create your format catalog in a permanent location.

There are 2 ways to make a format catalog and add formats to it:
1) hard code your format values (and pictures) in PROC FORMAT code or
2) create your format from a SAS dataset.

I generally recommend mastering #1 before jumping into #2.

To master #1, here is the general order of things.

format_catalog.png

No matter which method you choose, to USE the format, you only need to reference it in a FORMAT statement (or other syntax like a PUT statement) like:
format myvar fmtname.;

I think it will be hard to master the #2 method and make a permanent format catalog from a dataset if you don't quite understand SAS libraries, data sets and how formats work.

The free Programming 1 class has a discussion of SAS formats and creating user-defined formats. The Programming 2 class shows how to make and use permanent formats.

cynthia

Occasional Contributor
Posts: 7

Re: Saving work.formats to a permanent location

[ Edited ]

to answer your first question: Work.data is from an imported SPSS data file. The formats already exist and work in my original program. They were created when importing the data into SAS. They are being placed into the work folder when I am importing them as I do not immediately want to create a SAS datafile. They already exist and they already work in the data set where I import and do my recoding. 

 

I need to figure out how to MOVE the formats out of the work folder to a permanant locations when I am creating a permanent SAS dataset that is being placed in the same location.

 

Unfortuantely, while I appreciate the very lengthy response, the formats already exist. I really do not want to hardcode 200+ of them. There has to be another way to accomplish this. 

 

If my proc format coding is incorrect, this is what I am asking for help with. I need to move an existing work.formats catalog with work.data to another permanent location. 

SAS Super FREQ
Posts: 8,820

Re: Saving work.formats to a permanent location

If you have existing formats and you can see them defined in the WORK.FORMATS temporary catalog, then SASKiwi gave you the correct answer to use PROC CATALOG to perform the copy.
cynthia
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 14 replies
  • 719 views
  • 1 like
  • 5 in conversation