BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PierreYvesILY
Pyrite | Level 9

hello dear SAS experts,

 

I typed the following Code to define a numeric Format out of a character one:

/* Monatsformate für Erfolgsplan 																*/
data erfgpln;
length start $8 label 8;
input start label;
datalines;
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
JanMoy 21
FebMoy 22
MarMoy 23
AprMoy 24
MaiMoy 25
JunMoy 26
JulMoy 27
AugMoy 28
SepMoy 29
OctMoy 30
NovMoy 31
DecMoy 32
Jahr 33
;
run;
data erfgplnf;
set erfgpln end=last;
retain fmtname 'Erfgplnf' type 'n';
output;
run;
proc format cntlin=erfgplnf fmtlib;run;

 

I got the following error message:

63         proc format cntlin=erfgplnf fmtlib;
ERROR: For format ERFGPLNF, this range is repeated, or values overlap: .-..

How can I fix this?

 

Regards

PY

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What does this phrase mean?

define a numeric Format out of a character one

Your start values have character strings "JanMoy" etc.  So to convert that into a format you would need a character format not a numeric format.

 

Is your goal to create an INFORMAT instead of a FORMAT?

In that case use J as the TYPE.

 

Then you could use the new INFORMAT with an INPUT statement or INPUT() function call.

number = input('JanMoy',erfgpln.);

 

 

 

View solution in original post

7 REPLIES 7
Reeza
Super User
Type must be C for a character format as your starting values, "start" is a character.
Once you change that it works fine.
Tom
Super User Tom
Super User

What does this phrase mean?

define a numeric Format out of a character one

Your start values have character strings "JanMoy" etc.  So to convert that into a format you would need a character format not a numeric format.

 

Is your goal to create an INFORMAT instead of a FORMAT?

In that case use J as the TYPE.

 

Then you could use the new INFORMAT with an INPUT statement or INPUT() function call.

number = input('JanMoy',erfgpln.);

 

 

 

PierreYvesILY
Pyrite | Level 9

thanks, but I still can't use this.

Goal: I want a Format or informat to turn a character variable into a numeric one.

I simplified the first dataset and typed:

 

/* Monatsformate für Erfolgsplan 																*/
data erfgpln;
length start $2 label 3;
input start label;
datalines;
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 21
N 22
O 23
P 24
Q 25
R 26
S 27
T 28
U 29
V 30
W 31
X 32
Y 33
;
run;
data erfgplnf;
set erfgpln end=last;
retain fmtname 'Erfgplnf' type 'f';
output;
run;
proc format cntlin=erfgplnf fmtlib; run;

I get the following Display in the Formats:

 

                            ----------------------------------------------------------------------------                            
                            |       FORMAT NAME: ERFGPLNF LENGTH:    2   NUMBER OF VALUES:    1        |                            
                            |   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:   2  FUZZ: STD       |                            
                            |--------------------------------------------------------------------------|                            
                            |START           |END             |LABEL  (VER. V7|V8   19MAR2021:17:30:29)|                            
                            |----------------+----------------+----------------------------------------|                            
                            |               .|               .|33                                      |                            
                            ----------------------------------------------------------------------------                            

which doesn't help to operate what I want.

 

What has to be modified?

PierreYvesILY
Pyrite | Level 9

I also typed :

 

data erfgplnf;
set erfgpln end=last;
retain fmtname 'Erfgplnf' type 'J';
output;
run;
proc format cntlin=erfgplnf fmtlib; run;

same result

Tom
Super User Tom
Super User

Note that formats convert values to text.  Informats convert text to values.

Numeric formats work on numeric values.  Character formats work on character values.  Numeric informats create numeric values.  Character informats create character values.

 

To convert text to numbers you need a numeric informat.

 

Your original data is fine for defining a numeric INFORMAT, just use 'J' as the TYPE.

789   data erfgplnf;
790     set erfgpln end=last;
791     retain fmtname 'Erfgplnf' type 'J';
792   run;

NOTE: There were 25 observations read from the data set WORK.ERFGPLN.
NOTE: The data set WORK.ERFGPLNF has 25 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


793   
794   proc format cntlin=erfgplnf fmtlib;
NOTE: Informat $ERFGPLNF has been output.
794 !                                    run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.13 seconds
      cpu time            0.03 seconds
Reeza
Super User
The code you've shown creates a format but doesn't really produce any output that you can see so not sure what's you're expecting to see in that output.
Show us how you intend to use this format and maybe we can help clarify how the code should be structured for your problem.
PierreYvesILY
Pyrite | Level 9

eza,

 

thank you very much for your help.

 

I posted a longer topic to explain my concern:

https://communities.sas.com/t5/New-SAS-User/Pb-when-I-use-an-informat-I-defined/td-p/727822

 

I hope this will clear the problem.

 

 

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 569 views
  • 5 likes
  • 3 in conversation