Hello,
I want to change the format of a variable to numeric
the actual format and informat is $28.
data IPO_list0;
set IPO_list0;
Asset_alloc_equity_net1 = input(Asset_alloc_equity_net, 8.);
run;
Hello,
I want to change the format of a variable to numeric
the actual format and informat is $28.
To change the type of a variable, you have to create a new one, convert the value with the INPUT function, drop the old variable, and rename the new one to the name of the old.
can you please give an example of numeric format
I know that I should write
data want;
set have;
format var ;
informat var;
run;
After 160+ posts here, it should be a breeze for you to write the code from my description.
Do that, and if you run into problems, post example data in usable form, and the complete log you got from the code you tried.
@sasphd wrote:
Hello,
I want to change the format of a variable to numeric
the actual format and informat is $28.
Please provide example values.
If a character variable holds 28 digits it can very well run into issues with computer precision when stored as numeric.
The largest integer values that can be stored reliably in SAS are below, first for Z/OS and second for Windows/UNIX flavors. Note that neither of these comes anywhere near 28 characters even with the commas, which are not part of the value.
72,057,594,037,927,936
|
9,007,199,254,740,992
|
Are you going to do arithmetic with the values? If not then they should remain character. If you will then you may have significant issues with computation and precision.
data IPO_list0;
set IPO_list0;
Asset_alloc_equity_net1 = input(Asset_alloc_equity_net, 8.);
run;
And now you add a little code:
data IPO_list0 (
drop=Asset_alloc_equity_net
rename=(Asset_alloc_equity_net1=Asset_alloc_equity_net)
);
set IPO_list0;
Asset_alloc_equity_net1 = input(Asset_alloc_equity_net, 8.);
run;
and you have effectively changed the type of the variable.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.