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

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

202.00E+1115443014 
202.00E+1115443014 
202.00E+1115443014 
203.00E+116271354 
203.00E+1110011524 
203.00E+1110051244 
205.00E+1115192524 
205.00E+1115214564 
205.00E+1115230324 
205.00E+1115357264 
205.00E+1115499014 
206.00E+1115328394 
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

6 REPLIES 6
andreas_lds
Jade | Level 19

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.

ChrisNZ
Tourmaline | Level 20

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.

 

 

Kurt_Bremser
Super User

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.

FreelanceReinh
Jade | Level 19

@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.

ballardw
Super User

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.

Khutjo
Calcite | Level 5

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-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
  • 6 replies
  • 656 views
  • 0 likes
  • 6 in conversation