BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

 

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

 

Ronein
Onyx | Level 15

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 728 views
  • 1 like
  • 2 in conversation