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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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