Help using Base SAS procedures

Need help with combining 2 libraries using proc format

Reply
Contributor
Posts: 40

Need help with combining 2 libraries using proc format

hi,

I have 2 format catalog that I want to combine.

For example, there is a format catalog with different format names - fmtlib1

                    Also there is another format catalog for just one format name(fmtnm1) which is in "fmtlib1" - fmtlib2

How can I combine both format names and update fmtlib1 with all values from  "fmtlib2" for fmtnm1 ? (It will be just update, not overwrite and fmtlib1 should have all formats remain same except for fmtnm1)

thanks and appreciate any help!!

Super User
Posts: 5,082

Re: Need help with combining 2 libraries using proc format

sasbasis,

Be sure to back up the format libraries before attempting to make permanent changes!

SAS lets you transfer data from a SAS data set to a format library, and vice versa.  Here is one approach (untested, so you may need to tweak the code):

proc format library=libname.fmtlib1 cntlout=show_me_fmtlib1;

run;

proc format library=libname.fmtlib2 cntlout=show_me_fmtlib2;

run;

* Not sure if sorting is necessary, but just in case;

proc sort data=show_me_fmtlib1;

   by fmtname start end;

run;

proc sort data=show_me_fmtlib2;

   by fmtname start end;

run;

data combined;

   merge show_me_fmtlib1 show_me_fmtlib2;

   by fmtname start end;

run;

proc format library=libname.fmtlib1 cntlin=combined;

run;

There is no guarantee that the updates will work.  It is possible that fmtlib2 contains range definitions for fmtnm1 that incompatible with the definitions in fmtlib1.  But running the program will tell you if there is a problem.

Contributor
Posts: 40

Re: Need help with combining 2 libraries using proc format

I want to confirm one more doubt.

fmtlib1has so many format names and fmtlib2 has one format name. So what I wanted to output is: all formats that are there in fmtlib1 + updated format name which is common to both libraries (should include values from fmtlib1 & fmtlib2 for that common format name). Thanks!!

PROC Star
Posts: 7,363

Re: Need help with combining 2 libraries using proc format

Can you provide an example of the two formats that overlap?  Do either or both have an assignment for other?  Do they share any assignments?  Does either use a range that would conflict with the other?

Contributor
Posts: 40

Re: Need help with combining 2 libraries using proc format

I don't understand 2nd part of your question.

Here is how formats looked:

fmtlib1 had formats fmt1, fmt2, fmt3 etc

fmtlib2 has fmt2.

So when I combine both formats, resulting format should have fmt1, fmt2(with values from fmtlib1 & fmtlib2 - after deduping), fmt3 etc.

thanks in advance for any ideas!!

PROC Star
Posts: 7,363

Re: Need help with combining 2 libraries using proc format

What I would like to see are the new and old versions of fmt2.

You just mentioned deduping thus, apparently, there are redundant entries.  My question is regarding the complexities of those entries.

It would be one thing it they were just:

old "a"=1

      "b=2;

new "b"=2

       "c"=3

but quite another if they were in a form like:

old "a","b"=1

       "c"=2;

new "a","b","d"=1

       "c","e"=2;

Super User
Posts: 5,082

Re: Need help with combining 2 libraries using proc format

Yes, the solution that I provided should do that.

Notice that the contents of fmtlib1 and fmtlib2 get combined in the MERGE, so both get used to regenerate fmtlib1.

It is possible that this won't work, depending on how the additional entries mesh together.  For example:

In fmtlib1, fmtnm1 contains this range:  20 - 30 = 'Medium'

In fmtlib2, fmtnm1 contains this range:  25 - 35 = 'Medium'

That's why you need to run the program and see if it works.

And as forewarned, make copies of the two format libraries first.

Good luck.

Ask a Question
Discussion stats
  • 6 replies
  • 210 views
  • 0 likes
  • 3 in conversation