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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 751 views
  • 3 likes
  • 3 in conversation