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

Hi Experts,

 

Can anyone tell me why i am getting exponential value for third observation.

 

data test;
infile datalines dlm=',';
input name $ salary;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,4524542145214
sagar adirala bahu,111111111111
;
run;

 

 

expo.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Length and Formats are not the same thing. 

 

A format controls how many digits/characters are displayed

A length controls how many digits/characters are stored in the underlying system. 

 

data test;
infile datalines dlm=',';
length salary 8;
format salary best32.;
input name $ salary;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,9007199254740992
sagar adirala bahu,72057594037927936
;
run;

proc print data=test;
format salary best32.;
run;

 

 

 

 

View solution in original post

9 REPLIES 9
Reeza
Super User

Value is too wide 13chars and default format won't display it correctly. 

Explicitly specify your format.

 

data test;
infile datalines dlm=',';
input name $ salary;
format name $50. salary Best32.;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,4524542145214
sagar adirala bahu,111111111111
;
run;

@Rahul_SAS wrote:

Hi Experts,

 

Can anyone tell me why i am getting exponential value for third observation.

 

data test;
infile datalines dlm=',';
input name $ salary;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,4524542145214
sagar adirala bahu,111111111111
;
run;

 

 

expo.PNG


 

Rahul_SAS
Quartz | Level 8

Hi Reeza,

 

Completely agree with your statement.

However here, I have 2 questions-

1. SAS supports default 8 bytes so only 5 digits should have been read not 12 digits.

2. I have an understanding that while creating a table in a data warehouse we should keep numeric columns so that it will occupy less storage whereas character columns will consume more storage space. 

Reeza
Super User

Regarding 1, see this page. 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p0dv87zb3bnse6n1mqo360be70qr.htm

 

8 bytes is numbers as large as  9,007,199,254,740,992

 

2. Yes they should be numeric, so use 32. if you'd like. 

I said character, but I was referring to the number of digits. The default width of the format doesn't display the desired amount of digits is more accurate. 

 


@Rahul_SAS wrote:

Hi Reeza,

 

Completely agree with your statement.

However here, I have 2 questions-

1. SAS supports default 8 bytes so only 5 digits should have been read not 12 digits.

2. I have an understanding that while creating a table in a data warehouse we should keep numeric columns so that it will occupy less storage whereas character columns will consume more storage space. 


 

ballardw
Super User

@Rahul_SAS wrote:

Hi Reeza,

 

Completely agree with your statement.

 

1. SAS supports default 8 bytes so only 5 digits should have been read not 12 digits.


You want to look at what "fits" in 8 bytes. Why would 8 bytes be restricted to 5 digits ever?

From documentation for Windows

Significant Digits and Largest Integer by Length for SAS Variables under Windows
Length in Bytes
Largest Integer Represented Exactly
Exponential Notation
Significant Digits Retained
3
8,192
213
3
4
2,097,152
221
6
5
536,870,912
229
8
6
137,438,953,472
237
11
7
35,184,372,088,832
245
13
8
9,007,199,254,740,992
253
15
 
Rahul_SAS
Quartz | Level 8

Hi Reeza/Ballardw,

 

Even using the values given in the table are not working as expected.

 

data test;
infile datalines dlm=',';
input name $ salary 8.;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,9007199254740992
sagar adirala bahu,72057594037927936
;
run;

Its returning only 8 digits even after applying 8. format.

 

Largest Integer That Can Be Safely Stored in a Given Length

When Variable Length Equals ...

Largest Integer

z/OS

Largest Integer

Windows or UNIX

2

256

not applicable

3

65,536

8,192

4

16,777,216

2,097,152

5

4,294,967,296

536,870,912

6

1,099,511,627,776

137,438,953,472

7

281,474,946,710,656

35,184,372,088,832

8 (default)

72,057,594,037,927,936

9,007,199,254,740,992

 

Significant Digits and Largest Integer by Length for SAS Variables under Windows
Length in Bytes
Largest Integer Represented Exactly
Exponential Notation
Significant Digits Retained
3
8,192
213
3
4
2,097,152
221
6
5
536,870,912
229
8
6
137,438,953,472
237
11
7
35,184,372,088,832
245
13
8
9,007,199,254,740,992
253
15

 

Reeza
Super User

Length and Formats are not the same thing. 

 

A format controls how many digits/characters are displayed

A length controls how many digits/characters are stored in the underlying system. 

 

data test;
infile datalines dlm=',';
length salary 8;
format salary best32.;
input name $ salary;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,9007199254740992
sagar adirala bahu,72057594037927936
;
run;

proc print data=test;
format salary best32.;
run;

 

 

 

 

Reeza
Super User
And an informat controls tells SAS how the variable should be read in, ie what format to expect the variable in.
AMSAS
SAS Super FREQ

@Rahul_SAS You are confusing 3 different SAS terms

  1. Length - This is the amount of "Ram/Disk used to store a variable"
  2. Format - This is the way to display a variable 
  3. Informat - This is the way SAS reads a variable

In your code (below) you are telling SAS to create a variable salary, it will have a default length of 8 bytes, by reading just 8 numeric characters
So your 1st record which has 400000455225 as the second variable, SAS only reads the first 8 characters 400000455

data test;
infile datalines dlm=',';
input name $ salary 8.;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,9007199254740992
sagar adirala bahu,72057594037927936
;
run;
Tom
Super User Tom
Super User

PROC PRINT will default to using BEST12. format to display numeric variables that have no format attached to them.

Use a different format to display the variable.

data test;
  infile datalines dsd ;
  input name :$30. salary;
  format salary comma20.;
datalines;
venkat pati raju,400000455225
vivek rattakonda murali,425
kiran kumar segu,4524542145214
sagar adirala bahu,111111111111
;

proc print;
run;

Tom_0-1652374665724.png

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 9 replies
  • 1848 views
  • 3 likes
  • 5 in conversation