Can I please get assistance on reading a numeric field
I'm trying to read field two and it needs to appear with the "E" sign
20 | 2.00E+11 | 154430 | 1 | 4 | |
20 | 2.00E+11 | 154430 | 1 | 4 | |
20 | 2.00E+11 | 154430 | 1 | 4 | |
20 | 3.00E+11 | 62713 | 5 | 4 | |
20 | 3.00E+11 | 100115 | 2 | 4 | |
20 | 3.00E+11 | 100512 | 4 | 4 | |
20 | 5.00E+11 | 151925 | 2 | 4 | |
20 | 5.00E+11 | 152145 | 6 | 4 | |
20 | 5.00E+11 | 152303 | 2 | 4 | |
20 | 5.00E+11 | 153572 | 6 | 4 | |
20 | 5.00E+11 | 154990 | 1 | 4 | |
20 | 6.00E+11 | 153283 | 9 | 4 |
SAS provides a format and informat for scientific notation:
data want;
infile datalines dlm='09'x dsd truncover;
input
f1
f2 :e8.
f3
f4
f5
;
format f2 e9.;
datalines;
20 2.00E+11 154430 1 4
20 2.00E+11 154430 1 4
;
The display format needs an additional byte for length because it needs to accomodate an eventual sign.
Appearance of data is controlled by assigning the appropriate format to the variable. Please be a bit more specific: post the code and log you used to read the data (as text using running-man-icon), so that we can see what happens.
You mean you are trying to write that number so that it can be read in full.
The way numbers are displayed is controlled by formats. It looks like your format is too short.
Use a longer format such as comma20. for example.
SAS provides a format and informat for scientific notation:
data want;
infile datalines dlm='09'x dsd truncover;
input
f1
f2 :e8.
f3
f4
f5
;
format f2 e9.;
datalines;
20 2.00E+11 154430 1 4
20 2.00E+11 154430 1 4
;
The display format needs an additional byte for length because it needs to accomodate an eventual sign.
@Kurt_Bremser wrote:
SAS provides a format and informat for scientific notation:
But the informat Ew.d is just an alias of the default informat w.d, so it can be omitted.
Details are important.
If the "data" is the appearance in Excel then that is just the result of the Excel display showing something that may be numeric (or not, it does this with Phone numbers, social security and account ids as well) when the display column is narrower than needed to display all of the digits.
HOW are you attempting to "read" this? SAS does so pretty easily with no coaching IF that is what you want:
data junk; input a b c d e; datalines; 20 2.00E+11 154430 1 4 20 2.00E+11 154430 1 4 20 2.00E+11 154430 1 4 20 3.00E+11 62713 5 4 20 3.00E+11 100115 2 4 20 3.00E+11 100512 4 4 20 5.00E+11 151925 2 4 20 5.00E+11 152145 6 4 20 5.00E+11 152303 2 4 20 5.00E+11 153572 6 4 20 5.00E+11 154990 1 4 20 6.00E+11 153283 9 4
;
I strongly suggest expanding the width of the column and probably changing how you are reading the data as I suspect that value should not be numeric to begin with.
I got it right
data Risk_Detail;
infile "file name',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat Name $100.;
informat registration_number $50.;
informat number best32.;
informat Service_Provider_No best32.;
format Name $100.;
format registration_number $50.;
format number best32.;
format Service_Provider_No best32.;
input
Name $
registration_number $
number
Service_Provider_No
;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.