DATA Step, Macro, Functions and more

change format for data

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

change format for data

APPLICATION

NEWSAPPLICATION
S1  
S2  
S33E+14300000002035314
S43E+14300000002227110

Hello,

Above is a piece of my table, what I want to do is when New=blank, then new=sapplication;

DATA want;

SET have;

IF NEW = '.' THEN DO;

NEW= TRIM(PUT(SAPPLICATION,15.-L))

;

END;

run;

 

but the new is still in the format of 3E+14. can someone help this? thank you.


Accepted Solutions
Solution
‎01-30-2017 09:33 AM
Super User
Posts: 5,085

Re: change format for data

So NEW should be numeric.

 

It looks like SAPPLICATION is also numeric.  Correct me if I'm wrong about that, but the use of the PUT function suggests that it is numeric.

 

In that case, the correct syntax would be:

 

if new = . then new = sapplication;

format new 15.;

 

If this still generates scientific notation, that's a result of the printing format used when printing not being physically wide enough to hold 15 digits, not a result of what is contained in the data.

View solution in original post


All Replies
Contributor
Posts: 33

Re: change format for data

Could you create NEW as character instead of numeric or do you need it for calculations? It looks like you're running into long number issues.

Contributor
Posts: 28

Re: change format for data

It is better to keep it as numeric.
Occasional Contributor
Posts: 15

Re: change format for data

You may want to try formatting NEW with the best32. format when you read the data in.

Super User
Posts: 10,516

Re: change format for data

DATA want;

SET have;

IF NEW = '.' THEN DO;

NEW= TRIM(PUT(SAPPLICATION,15.-L))

;

FORMAT New best16.;

END;

run;

 

SAS Formats control appearance of values but are not changing the actual values.

Contributor
Posts: 28

Re: change format for data

Thank you.
Solution
‎01-30-2017 09:33 AM
Super User
Posts: 5,085

Re: change format for data

So NEW should be numeric.

 

It looks like SAPPLICATION is also numeric.  Correct me if I'm wrong about that, but the use of the PUT function suggests that it is numeric.

 

In that case, the correct syntax would be:

 

if new = . then new = sapplication;

format new 15.;

 

If this still generates scientific notation, that's a result of the printing format used when printing not being physically wide enough to hold 15 digits, not a result of what is contained in the data.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 187 views
  • 1 like
  • 5 in conversation