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
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.
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.
Hi KurtBremser,
Attached the sas coding, please advice(let me know if i missunderstood your request).
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-
;
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-
;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.