DATA Step, Macro, Functions and more

Data step not working with ascii fixed format file

Reply
N/A
Posts: 0

Data step not working with ascii fixed format file

Hi all,

It's been a while since I have been a regular SAS user. I know that I've encountered this problem before, but can't remember the solution. I would really appreciate your help.

I have a fixed format ascii file, and many of the fields have missing values.
But when I import the file, instead of setting the value of a field that is missing to missing, sas skips to the next non-missing character string and populating every missing field with that.

I sure would appreciate any assistance!!

Thanks,

Barb

**************************************************************************
* Here is my data step:
**************************************************************************
libname client 'G:\CLIENTS\SAS_INPUT_DATA';

data client.admissions (drop=DateAdmitChar DateDischargeChar);
format DateAdmit DateDischarge mmddyy10.;
infile 'G:\CLIENTS\SAS_INPUT_DATA\admissions_with_drg.out'
LRECL=617
truncover;
input
@1 PATAGE :3.
@4 GENDER :$CHAR1.
@5 DateAdmitChar :$CHAR10.
@15 DateDischargeChar :$CHAR10.
@25 LOS :3.
@30 AdmitDx01 :$CHAR5.
@35 AdmitDx02 :$CHAR5.
@40 AdmitDx03 :$CHAR5.
@45 AdmitDx04 :$CHAR5.
@50 AdmitDx05 :$CHAR5.
@55 AdmitDx06 :$CHAR5.
@60 AdmitDx07 :$CHAR5.
@65 AdmitDx08 :$CHAR5.
@70 AdmitDx09 :$CHAR5.
@75 AdmitDx10 :$CHAR5.
@80 AdmitDx11 :$CHAR5.
@85 AdmitDx12 :$CHAR5.
@90 AdmitDx13 :$CHAR5.
@95 AdmitDx14 :$CHAR5.
@100 AdmitDx15 :$CHAR5.
@105 AdmitDx16 :$CHAR5.
@110 AdmitDx17 :$CHAR5.
@115 AdmitDx18 :$CHAR5.
@120 AdmitDx19 :$CHAR5.
@125 AdmitDx20 :$CHAR5.
@130 AdmitDx21 :$CHAR5.
@135 AdmitDx22 :$CHAR5.
@140 AdmitDx23 :$CHAR5.
@145 AdmitDx24 :$CHAR5.
@150 AdmitDx25 :$CHAR5.
@155 AdmitDx26 :$CHAR5.
@160 AdmitDx27 :$CHAR5.
@165 AdmitDx28 :$CHAR5.
@170 AdmitDx29 :$CHAR5.
@175 AdmitDx30 :$CHAR5.
@180 AdmitDx31 :$CHAR5.
@185 AdmitDx32 :$CHAR5.
@190 AdmitDx33 :$CHAR5.
@195 AdmitDx34 :$CHAR5.
@200 AdmitDx35 :$CHAR5.
@205 AdmitDx36 :$CHAR5.
@210 AdmitDx37 :$CHAR5.
@215 AdmitDx38 :$CHAR5.
@220 AdmitDx39 :$CHAR5.
@225 AdmitDx40 :$CHAR5.
@230 AdmitDx41 :$CHAR5.
@235 AdmitDx42 :$CHAR5.
@240 AdmitDx43 :$CHAR5.
@245 AdmitDx44 :$CHAR5.
@250 AdmitDx45 :$CHAR5.
@255 AdmitDx46 :$CHAR5.
@260 AdmitDx47 :$CHAR5.
@265 AdmitDx48 :$CHAR5.
@270 AdmitDx49 :$CHAR5.
@275 AdmitDx50 :$CHAR5.
@285 AdmitProc01 :$CHAR5.
@290 AdmitProc02 :$CHAR5.
@295 AdmitProc03 :$CHAR5.
@300 AdmitProc04 :$CHAR5.
@305 AdmitProc05 :$CHAR5.
@310 AdmitProc06 :$CHAR5.
@315 AdmitProc07 :$CHAR5.
@320 AdmitProc08 :$CHAR5.
@325 AdmitProc09 :$CHAR5.
@330 AdmitProc10 :$CHAR5.
@335 AdmitProc11 :$CHAR5.
@340 AdmitProc12 :$CHAR5.
@345 AdmitProc13 :$CHAR5.
@350 AdmitProc14 :$CHAR5.
@355 AdmitProc15 :$CHAR5.
@360 AdmitProc16 :$CHAR5.
@365 AdmitProc17 :$CHAR5.
@370 AdmitProc18 :$CHAR5.
@375 AdmitProc19 :$CHAR5.
@380 AdmitProc20 :$CHAR5.
@385 AdmitProc21 :$CHAR5.
@390 AdmitProc22 :$CHAR5.
@400 AdmitProc23 :$CHAR5.
@405 AdmitProc24 :$CHAR5.
@410 AdmitProc25 :$CHAR5.
@415 AdmitProc26 :$CHAR5.
@420 AdmitProc27 :$CHAR5.
@425 AdmitProc28 :$CHAR5.
@430 AdmitProc29 :$CHAR5.
@435 AdmitProc30 :$CHAR5.
@440 AdmitProc31 :$CHAR5.
@445 AdmitProc32 :$CHAR5.
@450 AdmitProc33 :$CHAR5.
@455 AdmitProc34 :$CHAR5.
@460 AdmitProc35 :$CHAR5.
@465 AdmitProc36 :$CHAR5.
@470 AdmitProc37 :$CHAR5.
@475 AdmitProc38 :$CHAR5.
@480 AdmitProc39 :$CHAR5.
@485 AdmitProc40 :$CHAR5.
@490 AdmitProc41 :$CHAR5.
@495 AdmitProc42 :$CHAR5.
@500 AdmitProc43 :$CHAR5.
@505 AdmitProc44 :$CHAR5.
@510 AdmitProc45 :$CHAR5.
@515 AdmitProc46 :$CHAR5.
@520 AdmitProc47 :$CHAR5.
@525 AdmitProc48 :$CHAR5.
@530 AdmitProc49 :$CHAR5.
@535 AdmitProc50 :$CHAR5.
@540 PATID :$CHAR20.
@565 HOSPITALID: $CHAR20.
@590 AdmitID: $CHAR15.
@608 DischStatus: $CHAR2.
@615 DRG: 3.
;
DateAdmit = mdy( substr(DateAdmitChar,6,2) , substr(DateAdmitChar,9,2) , substr(DateAdmitChar,1,4) );
DateDischarge = mdy( substr(DateDischargeChar,6,2) , substr(DateDischargeChar,9,2) , substr(DateDischargeChar,1,4) );
run;

**************************************************************************
* Here is the log (no errors, everything looks like it ran fine):
**************************************************************************
NOTE: Libref CLIENT was successfully assigned as follows:
Engine: V9
Physical Name: G:\CLIENTS\SAS_INPUT_DATA
987
988 data client.admissions (drop=DateAdmitChar DateDischargeChar);
989 format DateAdmit DateDischarge mmddyy10.;
990 infile 'G:\CLIENTS\SAS_INPUT_DATA\admissions_with_drg.out'
991 LRECL=617
992 truncover;
993 input
994 @1 PATAGE :3.
995 @4 GENDER :$CHAR1.
996 @5 DateAdmitChar :$CHAR10.
997 @15 DateDischargeChar :$CHAR10.
998 @25 LOS :3.
999 @30 AdmitDx01 :$CHAR5.
1000 @35 AdmitDx02 :$CHAR5.
1001 @40 AdmitDx03 :$CHAR5.
1002 @45 AdmitDx04 :$CHAR5.
1003 @50 AdmitDx05 :$CHAR5.
1004 @55 AdmitDx06 :$CHAR5.
1005 @60 AdmitDx07 :$CHAR5.
1006 @65 AdmitDx08 :$CHAR5.
1007 @70 AdmitDx09 :$CHAR5.
1008 @75 AdmitDx10 :$CHAR5.
1009 @80 AdmitDx11 :$CHAR5.
1010 @85 AdmitDx12 :$CHAR5.
1011 @90 AdmitDx13 :$CHAR5.
1012 @95 AdmitDx14 :$CHAR5.
1013 @100 AdmitDx15 :$CHAR5.
1014 @105 AdmitDx16 :$CHAR5.
1015 @110 AdmitDx17 :$CHAR5.
1016 @115 AdmitDx18 :$CHAR5.
1017 @120 AdmitDx19 :$CHAR5.
1018 @125 AdmitDx20 :$CHAR5.
1019 @130 AdmitDx21 :$CHAR5.
1020 @135 AdmitDx22 :$CHAR5.
1021 @140 AdmitDx23 :$CHAR5.
1022 @145 AdmitDx24 :$CHAR5.
1023 @150 AdmitDx25 :$CHAR5.
1024 @155 AdmitDx26 :$CHAR5.
1025 @160 AdmitDx27 :$CHAR5.
1026 @165 AdmitDx28 :$CHAR5.
1027 @170 AdmitDx29 :$CHAR5.
1028 @175 AdmitDx30 :$CHAR5.
1029 @180 AdmitDx31 :$CHAR5.
1030 @185 AdmitDx32 :$CHAR5.
1031 @190 AdmitDx33 :$CHAR5.
1032 @195 AdmitDx34 :$CHAR5.
1033 @200 AdmitDx35 :$CHAR5.
1034 @205 AdmitDx36 :$CHAR5.
1035 @210 AdmitDx37 :$CHAR5.
1036 @215 AdmitDx38 :$CHAR5.
1037 @220 AdmitDx39 :$CHAR5.
1038 @225 AdmitDx40 :$CHAR5.
1039 @230 AdmitDx41 :$CHAR5.
1040 @235 AdmitDx42 :$CHAR5.
1041 @240 AdmitDx43 :$CHAR5.
1042 @245 AdmitDx44 :$CHAR5.
1043 @250 AdmitDx45 :$CHAR5.
1044 @255 AdmitDx46 :$CHAR5.
1045 @260 AdmitDx47 :$CHAR5.
1046 @265 AdmitDx48 :$CHAR5.
1047 @270 AdmitDx49 :$CHAR5.
1048 @275 AdmitDx50 :$CHAR5.
1049 @285 AdmitProc01 :$CHAR5.
1050 @290 AdmitProc02 :$CHAR5.
1051 @295 AdmitProc03 :$CHAR5.
1052 @300 AdmitProc04 :$CHAR5.
1053 @305 AdmitProc05 :$CHAR5.
1054 @310 AdmitProc06 :$CHAR5.
1055 @315 AdmitProc07 :$CHAR5.
1056 @320 AdmitProc08 :$CHAR5.
1057 @325 AdmitProc09 :$CHAR5.
1058 @330 AdmitProc10 :$CHAR5.
1059 @335 AdmitProc11 :$CHAR5.
1060 @340 AdmitProc12 :$CHAR5.
1061 @345 AdmitProc13 :$CHAR5.
1062 @350 AdmitProc14 :$CHAR5.
1063 @355 AdmitProc15 :$CHAR5.
1064 @360 AdmitProc16 :$CHAR5.
1065 @365 AdmitProc17 :$CHAR5.
1066 @370 AdmitProc18 :$CHAR5.
1067 @375 AdmitProc19 :$CHAR5.
1068 @380 AdmitProc20 :$CHAR5.
1069 @385 AdmitProc21 :$CHAR5.
1070 @390 AdmitProc22 :$CHAR5.
1071 @400 AdmitProc23 :$CHAR5.
1072 @405 AdmitProc24 :$CHAR5.
1073 @410 AdmitProc25 :$CHAR5.
1074 @415 AdmitProc26 :$CHAR5.
1075 @420 AdmitProc27 :$CHAR5.
1076 @425 AdmitProc28 :$CHAR5.
1077 @430 AdmitProc29 :$CHAR5.
1078 @435 AdmitProc30 :$CHAR5.
1079 @440 AdmitProc31 :$CHAR5.
1080 @445 AdmitProc32 :$CHAR5.
1081 @450 AdmitProc33 :$CHAR5.
1082 @455 AdmitProc34 :$CHAR5.
1083 @460 AdmitProc35 :$CHAR5.
1084 @465 AdmitProc36 :$CHAR5.
1085 @470 AdmitProc37 :$CHAR5.
1086 @475 AdmitProc38 :$CHAR5.
1087 @480 AdmitProc39 :$CHAR5.
1088 @485 AdmitProc40 :$CHAR5.
1089 @490 AdmitProc41 :$CHAR5.
1090 @495 AdmitProc42 :$CHAR5.
1091 @500 AdmitProc43 :$CHAR5.
1092 @505 AdmitProc44 :$CHAR5.
1093 @510 AdmitProc45 :$CHAR5.
1094 @515 AdmitProc46 :$CHAR5.
1095 @520 AdmitProc47 :$CHAR5.
1096 @525 AdmitProc48 :$CHAR5.
1097 @530 AdmitProc49 :$CHAR5.
1098 @535 AdmitProc50 :$CHAR5.
1099 @540 PATID :$CHAR20.
1100 @565 HOSPITALID: $CHAR20.
1101 @590 AdmitID: $CHAR15.
1102 @608 DischStatus: $CHAR2.
1103 @615 DRG: 3.
1104 ;
1105 DateAdmit = mdy( substr(DateAdmitChar,6,2) , substr(DateAdmitChar,9,2) ,
1105! substr(DateAdmitChar,1,4) );
1106 DateDischarge = mdy( substr(DateDischargeChar,6,2) ,
1106! substr(DateDischargeChar,9,2) , substr(DateDischargeChar,1,4) );
1107 run;

NOTE: Character values have been converted to numeric values at the places given by:
(Line)Smiley SadColumn).
1105:22 1105:50 1105:78 1106:26 1106:58 1106:90
NOTE: The infile 'G:\CLIENTS\SAS_INPUT_DATA\admissions_with_drg.out' is:
File Name=G:\CLIENTS\SAS_INPUT_DATA\admissions_with_drg.out,
RECFM=V,LRECL=617

NOTE: 872 records were read from the infile
'G:\CLIENTS\SAS_INPUT_DATA\admissions_with_drg.out'.
The minimum record length was 617.
The maximum record length was 617.
One or more lines were truncated.
NOTE: The data set CLIENT.ADMISSIONS has 872 observations and 110 variables.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.04 seconds
Valued Guide
Posts: 2,177

Re: Data step not working with ascii fixed format file

Posted in reply to deleted_user
those : (colon) characters tell the input handling to move on to the next non-blank character. So, if you actually want to read at the target column, remove those : characters .
If blank/missing data is acceptable and generating errors, use the ?? informat modifier to suppress emssages.

good luck

PeterC
Occasional Contributor
Posts: 9

Re: Data step not working with ascii fixed format file

in stead of truncover try using missover

Ask a Question
Discussion stats
  • 2 replies
  • 204 views
  • 0 likes
  • 3 in conversation