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 -
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;
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.
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 -
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.
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;
Thank you both, that's what I was looking for 🙂
- Cheers -
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 25. Read more here about why you should contribute and what is in it for you!
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.