BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
msawdey1231
Calcite | Level 5

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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

14 REPLIES 14
Shmuel
Garnet | Level 18

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.

msawdey1231
Calcite | Level 5

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 

Reeza
Super User

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.  

msawdey1231
Calcite | Level 5

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. 

Cynthia_sas
SAS Super FREQ
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
msawdey1231
Calcite | Level 5

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?

Reeza
Super User

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'. 

msawdey1231
Calcite | Level 5

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.)

SASKiwi
PROC Star

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);

 

Reeza
Super User

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;

msawdey1231
Calcite | Level 5

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

Cynthia_sas
SAS Super FREQ

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

msawdey1231
Calcite | Level 5

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. 

Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 14 replies
  • 9334 views
  • 3 likes
  • 5 in conversation