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
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
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
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
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.