BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sleretrano
Quartz | Level 8

I'm on SAS version 5.1.

 

In a database I have a numeric variable called CtrcN whose entries are 14 digit numbers. They are displayed as, for example, 4.2000001E13 instead of 42000001251100.

In order to try to fix this I use the following code.

DATA nameofoutputdatabase;
SET nameofinputdatabse;
CtrcN_Aux=input(CtrcN,BEST14.);
RUN;

(I used an auxiliary variable just to avoid possible issues with writing over the same variable).

The variable CtrcN_Aux still comes looking like 4.2000001E13.

A possible fix to this is to change it into a character variable, but I don't want this. Another one is to define the format in a PROC SQL, which I also do not want to do.

What can I do in order to display the variable as 42000001251100 instead of 4.2000001E13 by using a DATA ; SET ; RUN ;?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

hello,

 

try applying the format to the variable: format CtrcN best14.;

View solution in original post

6 REPLIES 6
Loko
Barite | Level 11

hello,

 

try applying the format to the variable: format CtrcN best14.;

sleretrano
Quartz | Level 8
Perfect. Simple and efficient.
Why isn't my method working, though?
Loko
Barite | Level 11

because input is for transforming character variable to numeric format. Your variable is already a numeric variable and if you check

the log you will notice the message:

 Numeric values have been converted to character values at the places given by: (Line):(Column)...

 

This means your numeric variable used in the function (CtrcN) is converted by sas to a character one using best12. format.

 

More on input:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000180357.htm

 

sleretrano
Quartz | Level 8
Thank you very much.

Very informative.
FreelanceReinh
Jade | Level 19

Hi @sleretrano,

 

-- I just notice that Loko has already given the explanation, while I was writing this --

 

I assume, with "database" you mean "SAS dataset." It was a good idea to store the result of the INPUT function in a new variable, because in general the expression input(CtrcN,BEST14.) returns a different value than CtrcN:

  1. Since the INPUT function expects a character expression as its first argument, the value in CtrcN is automatically converted to a character string (see corresponding NOTE in the log!) using the default numeric format BEST12., which turns 42000001251100 into "4.2000001E13". Please note that the information contained in the last six digits (251100) is already lost at this point!
  2. Reading the string "4.2000001E13" with informat BEST14. results in the number 4.2000001E13, i.e., 42000001000000.

 

This is not what you want. Instead, don't touch the numeric value and just apply an appropriate format like BEST14. for display purposes, as Loko has suggested. If all the numbers in CtrcN are integers of (up to) 14 digits, format 14. would do as well.

 

sleretrano
Quartz | Level 8
Thank you. I'm new to SAS, I don't know the standard terminology yet. This was helpful.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 2081 views
  • 1 like
  • 3 in conversation