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

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
Meteorite | Level 14

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 2 replies
  • 284 views
  • 1 like
  • 2 in conversation