Hello
I know how to build a numeric format from a data set.
I have tried to build a char format (called $Myfmt) but I get an error.
The error is in the run of :
proc format library=work cntlin=work.Myfmt;
run;
error code in Log window:
26 proc format library=work cntlin=work.Myfmt; ERROR: For format MYFMT, this range is repeated, or values overlap: .-.. 27 run;
What is the way to solve the error please?
/********** Build a numeric Format from a Dataset************/
/********** Build a numeric Format from a Dataset************/
/********** Build a numeric Format from a Dataset************/
Data format_tbl;
Input outcode outname $;
cards;
101 Aberdeen
102 Altrincham
103 Ashford
104 Barnsley
105 Basildon
106 Basingstoke
107 BathFirst
;
Run;
data work.outfmt(keep=start label fmtname);
set format_tbl(rename=(outcode=start outname=label));
fmtname='outfmt';
run;
proc format library=work cntlin=work.outfmt;
run;
/**Apply the format on a new data set***/
Data t;
format X outfmt.;
input X;
cards;
101
102
103
104
105
106
107
;
Run;
/********** Build a char Format from a Dataset************/
/********** Build a char Format from a Dataset************/
/********** Build a char Format from a Dataset************/
Data format_tbl;
Input outcode $ outname $;
cards;
A Alpha
B Beta
G Gama
;
Run;
data work.Myfmt(keep=start label fmtname);
set format_tbl(rename=(outcode=start outname=label));
fmtname='Myfmt';
run;
proc format library=work cntlin=work.Myfmt;
run;
/**Apply the format on a new data set***/
Data t;
format X $Myfmt.;
input Customer_ID X $;
cards;
1 A
2 A
3 B
4 A
5 G
;
Run;
Since you neither supplied type = "C" nor a leading $ in the fmtname, PROC FORMAT tries to build a numeric format. The character values will be invalid and all result in missing numeric values, causing the ranges to overlap.
Since you neither supplied type = "C" nor a leading $ in the fmtname, PROC FORMAT tries to build a numeric format. The character values will be invalid and all result in missing numeric values, causing the ranges to overlap.
Thanks,
Here is the solution that used your feedback:
/********** Build a char Format from a Dataset************/
/********** Build a char Format from a Dataset************/
/********** Build a char Format from a Dataset************/
Data format_tbl;
Input outcode $ outname $;
cards;
A Alpha
B Beta
G Gama
;
Run;
data work.Myfmt(keep=start label fmtname);
set format_tbl(rename=(outcode=start outname=label));
fmtname='$Myfmt';
run;
proc format library=work cntlin=work.Myfmt;
run;
/**Apply the format on a new data set***/
Data t;
format X $Myfmt.;
input Customer_ID X $;
cards;
1 A
2 A
3 B
4 A
5 G
;
Run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.