dear SAS experts,
I want to create a SAS Format using a dataset.
I used following code:
proc sort data=Filialstruktur_Ergaenzt (keep=filbez_bt_dashb filhb_bt_ec) noduplicate; by filbez_bt_dashb; run;
data fmt_filiale;
set Filialstruktur_Ergaenzt(rename=(filbez_bt_dashb=start filhb_bt_ec=label)) end=last;
retain fmtname 'Filiale';
output;
run;
proc format cntlin=fmt_filiale; run;
and I got the following error message:
26 data fmt_filiale;
27 set Filialstruktur_Ergaenzt(rename=(filbez_bt_dashb=start filhb_bt_ec=label)) end=last;
28 retain fmtname 'Filiale';
29 output;
30 run;
NOTE: There were 1072 observations read from the data set WORK.FILIALSTRUKTUR_ERGAENZT.
NOTE: The data set WORK.FMT_FILIALE has 1072 observations and 3 variables.
NOTE: Compressing data set WORK.FMT_FILIALE increased size by 12.50 percent.
Compressed is 9 pages; un-compressed would require 8 pages.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
31 proc format cntlin=fmt_filiale;
ERROR: This range is repeated, or values overlap: .-..
31 ! run;
WARNING: RUN statement ignored due to previous errors. Submit QUIT; to terminate the procedure.
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.00 seconds
cpu time 0.02 seconds
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1072 observations read from the data set WORK.FMT_FILIALE.
How can I correct this?
Thank you in advance,
Regards
PY
Since you want a format to translate from a character string, the name of the format should begin with a dollar sign.
retain fmtname '$Filiale';
Inspect and correct your data, so that it fulfills the requirements for a valid format.
Also do not forget to set the format type.
For in-depth help, we would need to see the whole dataset.
And if you want to prevent a duplicate of the key, you have to use nodupkey in the proc sort, not noduplicate, which is an alias for noduprec.
here is the complete dataset and then the problematic code:
data Filiale_Ergaenzung;
length filhb 5 filialname $35 ;
input filhb filialname ;
datalines;
91100 Sonstige_ZE
99991 Vermittler
99992 Online
99993 Direktvertrieb
99994 P7S1
99995 DrKlein
99999 Nicht_zustellbar
;
run;
proc sort data=Filiale_Ergaenzung nodupkey; by filialname;run;
data fmt;
set Filiale_Ergaenzung(rename=(filialname=start filhb=label)) end=last;
length start $35 label 5;
retain fmtname 'Filiale' type 'N';
output;
run;
proc format cntlin=fmt;run;
Your code is right, but since you are using the character values as start and label as numeric, then the type should be 'C'
data fmt;
set Filiale_Ergaenzung(rename=(filialname=start filhb=label)) end=last;
length start $35 label 5;
retain fmtname 'Filiale' type 'C';
output;
run;
proc format cntlin=fmt fmtlib;
run;
What should your format achieve? Map from a numeric ID to text, or from text to the numeric ID?
Hello Kurt,
I need : Filialname => filhb
If your filhb is actually numeric, then you would need an informat (type="I"), and use the INPUT() function to convert.
But since this is just a code, and not a number, I advise to store it as character in the first place, and use a character format.
Since you want a format to translate from a character string, the name of the format should begin with a dollar sign.
retain fmtname '$Filiale';
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.