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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

5 REPLIES 5
sagulolo
Quartz | Level 8

Hi KurtBremser,

 

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

Tom
Super User Tom
Super User

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

sagulolo
Quartz | Level 8

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-
;
Tom
Super User Tom
Super User

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.  

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