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

Hello Everybody

 

I have a problem, I have a DB for fifteen thousand lines. And this table has a specific column, which I call "CPF".

 

Well, in this CPF I have this type of sequence of numbers like this: "086.602.38373" "838.399.200.13"

I want to remove these points, so: "08660238373" "83839920013"

My table name: Gus If someone can write the entire code by pulling my CPF column from my Gus table.

 

Best regards,

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You cannot have values like  "086.602.38373" "838.399.200.13" in a numeric variable.  So your source variable must be a character string.  You can remove the periods from a character variable using the COMPRESS() function.  If you want to convert the string without periods into a number using the INPUT() function. Note that SAS stores all numbers as floating point so the maximum number of digits you have have is 16 (really 15).

data gus;
  infile CPF $20. ;
cards;
086.602.38373
838.399.200.13
;

data want;
  set gus;
  CPF_number = input(compress(CPF,'.'),32.);
  format CPF_number 16.;
run;

View solution in original post

14 REPLIES 14
PeterClemmensen
Tourmaline | Level 20

This is a character variable, correct?

GUST1
Fluorite | Level 6

GUST1_0-1611599650465.png

 

Reeza
Super User
Are you using an English language or a different language?

A numeric variable with the BEST format applied would not show up like that.
Tom
Super User Tom
Super User

You cannot have values like  "086.602.38373" "838.399.200.13" in a numeric variable.  So your source variable must be a character string.  You can remove the periods from a character variable using the COMPRESS() function.  If you want to convert the string without periods into a number using the INPUT() function. Note that SAS stores all numbers as floating point so the maximum number of digits you have have is 16 (really 15).

data gus;
  infile CPF $20. ;
cards;
086.602.38373
838.399.200.13
;

data want;
  set gus;
  CPF_number = input(compress(CPF,'.'),32.);
  format CPF_number 16.;
run;
GUST1
Fluorite | Level 6
data cpf;
infile cpf $20. ;
cards;
838.399.200.13
;
data want;
set gus;
cpf_number = input(compress(cpf,'.'),32.);
format cpf_number 16.;
run;
GUST1
Fluorite | Level 6

Its work!!

Thank you, so much!!

CVF                                                                New_cvf

GUST1_0-1611609205406.png

 

Tom
Super User Tom
Super User

Even without the periods you will probably still want to keep that variable as a string.  I doubt that you are going to take the MEAN or do other arithmetic on those values. 

GUST1
Fluorite | Level 6
I got you!
I will use to do a Inner join with another table, which I have just numbers without periods Do you think it's gonna work?
Tom
Super User Tom
Super User

If the other table has the values stored as a number then using a number would be easier to match.  With character strings you have to worry about leading zeros (or leading spaces). But that assumes the string of digits are short enough that they resulting integer can be stored exactly into the floating point numbers that SAS uses.

GUST1
Fluorite | Level 6

Actually,

I found this:

ERROR 23-2: Invalid option name $20..

 

Tom
Super User Tom
Super User

@GUST1 wrote:

Actually,

I found this:

ERROR 23-2: Invalid option name $20..

 


Show more of the log to see what you did.  You must have done something really creative to get SAS to think you had put the $20. into a place where it was expecting options.

GUST1
Fluorite | Level 6
Errors (1)
ERROR 23-2: Invalid option name $20..
Warnings (2)
WARNING: The data set WORK.CPF may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.CPF was not replaced because this step was stopped.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data cpf;
74 infile cpf $20.;
____
23
ERROR 23-2: Invalid option name $20..
75 cards;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CPF may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.CPF was not replaced because this step was stopped

 

Tom
Super User Tom
Super User

INPUT not INFILE

GUST1
Fluorite | Level 6
tkssss my dear

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 14 replies
  • 8709 views
  • 3 likes
  • 4 in conversation