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

Hi community,

I'd like to extend a format after it has been created and loaded.

Is there a quicker way than through the format table?

PROC FORMAT;
   *loaded in SAS at runtime, procedure not accessible;
   value a
      1='One'
      2='Two'
      3='Three'
      /* required: 99='Ninety nine'*/
   ;
RUN;

*Prepare format extension - export current format definition;
proc format cntlout=fmts lib=work;
   select a;
run;
*add 99 (Ninety nine) value;
data fmts;
   length label $200;
   set fmts end=last;
   max=200;default=200;length=200;
   output;
   if last then do;start=99; end=99; label='Ninety nine'; type=num; output;end;
run;
*Export and reload format;
proc format cntlin=fmts lib=work;
run;

data have;
   length a 8;
   a=1;output;
   a=2;output;
   a=3;output;
   a=99;output;
run;
data want;
   set have;
   format a a.;
run;
proc print;run;

I'm sure there is a more straight forward way but I can't figure it out right now.

Thanks

 

________________________

- Cheers -

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can make a NEW format that references the old format.

PROC FORMAT;
   *loaded in SAS at runtime, procedure not accessible;
   value a
      1='One'
      2='Two'
      3='Three'
   ;
   value newa 
     99='Ninety nine'
     other=[a.]
   ;
RUN;

View solution in original post

5 REPLIES 5
ballardw
Super User

Not much.

You could make a data set with the new values and the other properties for the format and append that to the cntlout data set instead of using the "if last" type of construct. This approach would be a bit more flexible in my opinion if you have more than a single value to add.

 

For what it may be worth, I have some formats that occasionally need to have values added. I keep the format code where I can find it easily and just modify the Proc format code. That way I always have a reference I can check if needed that is easier to reference than cntlout data sets.

Oligolas
Barite | Level 11

Ok thanks, I have in mind that a format can be loaded into another one.

I forgot what it was for. It was something like that:

PROC FORMAT;
   values
      a. /*Old format*/
      99='Ninety nine'
      ;
RUN;

Do you know what I mean?

________________________

- Cheers -

ballardw
Super User

Are you thinking of something like;

Proc format;
value newa
  1,2,3 = [a.]
   99 ='Ninetynine'
;

You can use the [ ] to apply an existing format to a range.

But I don't think you could do that to redefine the same format. You could try and see, I find things out all the time.

 

Tom
Super User Tom
Super User

You can make a NEW format that references the old format.

PROC FORMAT;
   *loaded in SAS at runtime, procedure not accessible;
   value a
      1='One'
      2='Two'
      3='Three'
   ;
   value newa 
     99='Ninety nine'
     other=[a.]
   ;
RUN;
Oligolas
Barite | Level 11

Thank you both, that's what I was looking for 🙂

________________________

- Cheers -

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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