DATA Step, Macro, Functions and more

infile few line to 1 row record, where to put trailsign.

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

infile few line to 1 row record, where to put trailsign.

Hi All,

 

trying to infile text file(fixed width) but stuck with the coding, my sample coding(sorry poor sample) as below:-

 

DATA TESTING ;
    INFILE DATALINES  MISSOVER;
    INPUT #1  H  $ 1-2 I $ 6-9  J 13-21   K 28-37
          #2  L  $ 1-2    M 13-21   N 20-37
          #3  O  $ 1-2    P 13-21   Q 20-37 ;
DATALINES;
D     ABC         .00
Ef                 23.40-         456.23
f                234.50-       10000.00-
;

 

undertstand informat trailsign can read number follow by negative sign, where should i put the trailsign to tell the Sas my data is number follow by negative since i need to inform the position of my data as well.

 

thanks in advance


Accepted Solutions
Solution
‎05-01-2017 10:02 AM
Super User
Super User
Posts: 7,083

Re: infile few line to 1 row record, where to put trailsign.

[ Edited ]

Look at this usage note.  http://support.sas.com/kb/9/675.html

Starting with SAS 9, the TRAILSGNw. informat is available to read
numeric values that contain a trailing minus sign.

So change your input specification from

P 13-21 

to

@13 P trailsgn9.  

 

PS.  Please use the TRUNCOVER option on the INFILE statement instead of the MISSOVER option.  It should not make a difference if you are reading from in-line card images like this data step.  But if you tried to read these trailing sign values from an external file it could make a huge difference.  If the lines in the file are not padded with spaces and the last value on the line is positive then you would end up telling SAS to read 9 characters (TRAILSGN9.) when only 8 would be available. With MISSOVER you will get a missing value. With TRUNCOVER you will get your value.  Here is an example:

filename test temp;
data _null_;
  file test;
  put '105.2-';
  put '105.2' ;
run;
data test1;
 infile test missover ;
  input x trailsgn6. ;
run;
data test2;
 infile test truncover ;
  input x trailsgn6. ;
run;
proc compare data=test1 compare=test2;
run;

In general you should always use TRUNCOVER instead of MISSOVER.  

View solution in original post


All Replies
Super User
Posts: 7,868

Re: infile few line to 1 row record, where to put trailsign.

Please post that step again, but use the {i} or "little running man" icon for posting. Putting code into the main posting window runs havoc on the formatting.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 59

Re: infile few line to 1 row record, where to put trailsign.

Posted in reply to KurtBremser

Hi KurtBremser,

 

Attached the sas coding, please advice(let me know if i missunderstood your request).

Attachment
Super User
Super User
Posts: 7,083

Re: infile few line to 1 row record, where to put trailsign.

To paste code or logs or other raw text use the Insert Code or Insert SAS Code icon on the menu bar in the editor form.

 

DATA TESTING ;
	INFILE DATALINES  MISSOVER;
	INPUT #1  H  $ 1-2 I $ 6-9  J 13-21   K 28-37
	      #2  L  $ 1-2    M 13-21   N 20-37
	      #3  O  $ 1-2    P 13-21   Q 20-37 ;
DATALINES;
D     ABC         .00
Ef	 			23.40-         456.23
f	 		   234.50-       10000.00-
;

Capture.PNG

Contributor
Posts: 59

Re: infile few line to 1 row record, where to put trailsign.

thank for highlighted else i won't notice the icon.

 

DATA TESTING ;
	INFILE DATALINES  MISSOVER;
	INPUT #1  H  $ 1-2 I $ 6-9  J 13-21   K 28-37
	      #2  L  $ 1-2    M 13-21   N 20-37
	      #3  O  $ 1-2    P 13-21   Q 20-37 ;
DATALINES;
D     ABC         .00
Ef	 			23.40-         456.23
f	 		   234.50-       10000.00-
;
Solution
‎05-01-2017 10:02 AM
Super User
Super User
Posts: 7,083

Re: infile few line to 1 row record, where to put trailsign.

[ Edited ]

Look at this usage note.  http://support.sas.com/kb/9/675.html

Starting with SAS 9, the TRAILSGNw. informat is available to read
numeric values that contain a trailing minus sign.

So change your input specification from

P 13-21 

to

@13 P trailsgn9.  

 

PS.  Please use the TRUNCOVER option on the INFILE statement instead of the MISSOVER option.  It should not make a difference if you are reading from in-line card images like this data step.  But if you tried to read these trailing sign values from an external file it could make a huge difference.  If the lines in the file are not padded with spaces and the last value on the line is positive then you would end up telling SAS to read 9 characters (TRAILSGN9.) when only 8 would be available. With MISSOVER you will get a missing value. With TRUNCOVER you will get your value.  Here is an example:

filename test temp;
data _null_;
  file test;
  put '105.2-';
  put '105.2' ;
run;
data test1;
 infile test missover ;
  input x trailsgn6. ;
run;
data test2;
 infile test truncover ;
  input x trailsgn6. ;
run;
proc compare data=test1 compare=test2;
run;

In general you should always use TRUNCOVER instead of MISSOVER.  

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 146 views
  • 2 likes
  • 3 in conversation