BookmarkSubscribeRSS Feed
sasbasls
Calcite | Level 5

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!!

6 REPLIES 6
Astounding
PROC Star

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.

sasbasls
Calcite | Level 5

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!!

art297
Opal | Level 21

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?

sasbasls
Calcite | Level 5

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!!

art297
Opal | Level 21

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;

Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 883 views
  • 0 likes
  • 3 in conversation