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

Hello, 

I want to change the format of a variable to numeric

the actual format and informat is $28.

1 ACCEPTED SOLUTION

Accepted Solutions
sasphd
Lapis Lazuli | Level 10

data IPO_list0;
set IPO_list0;
Asset_alloc_equity_net1 = input(Asset_alloc_equity_net, 8.);
run;

View solution in original post

7 REPLIES 7
sasphd
Lapis Lazuli | Level 10

Hello, 

I want to change the format of a variable to numeric

the actual format and informat is $28.

Kurt_Bremser
Super User

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.

sasphd
Lapis Lazuli | Level 10

can you please give an example of numeric format

I know that I should write

data want;

set have; 

format var ;

informat var; 

run;

Kurt_Bremser
Super User

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.

ballardw
Super User

@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.

sasphd
Lapis Lazuli | Level 10

data IPO_list0;
set IPO_list0;
Asset_alloc_equity_net1 = input(Asset_alloc_equity_net, 8.);
run;

Kurt_Bremser
Super User

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.

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1268 views
  • 3 likes
  • 3 in conversation