BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

Hi all,

I have a data where the debt_code is a character ype and format is $24. I want to change the debt_code to numeric. Can you suggest how to do it?

sample dataset:

Data Sample;
infile cards expandtabs;
input debt_code release_date :date9.;
format release_date date9.;
datalines ;
394013684 30-Mar-23
238505887 30-Mar-23
428101570 30-Mar-23
428101570 30-Mar-23
425461019 30-Mar-23
;
run;

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You will have to make a new variable since you want it to have a different type.

 

You can use an INPUT() function call to make a number from it.

debt_number = input(debt_code,32.);

You can use RENAME statement to change the variable names if want.

rename debt_code=debt_char debt_number=debt_code ;

BUT if the length of the digit strings in DEPT_CODE is longer than 16 then changing it to a number runs the risk of loosing precision.  The maximum integer that SAS can store is: 9,007,199,254,740,992

188  data _null_;
189    maxint=constant('exactint');
190    put maxint= comma32. ;
191    digits=length(strip(cats(maxint)));
192    put digits=;
193  run;

maxint=9,007,199,254,740,992
digits=16

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You will have to make a new variable since you want it to have a different type.

 

You can use an INPUT() function call to make a number from it.

debt_number = input(debt_code,32.);

You can use RENAME statement to change the variable names if want.

rename debt_code=debt_char debt_number=debt_code ;

BUT if the length of the digit strings in DEPT_CODE is longer than 16 then changing it to a number runs the risk of loosing precision.  The maximum integer that SAS can store is: 9,007,199,254,740,992

188  data _null_;
189    maxint=constant('exactint');
190    put maxint= comma32. ;
191    digits=length(strip(cats(maxint)));
192    put digits=;
193  run;

maxint=9,007,199,254,740,992
digits=16

 

SAS_Cares
SAS Employee

These may help: 

How to convert a character value to numeric in SAS https://communities.sas.com/t5/SAS-Communities-Library/How-to-convert-a-character-value-to-numeric-i...

Convert variable values from character to numeric or from numeric to character https://support.sas.com/kb/24/590.html

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 851 views
  • 3 likes
  • 3 in conversation