I have a input text file which has data in the below format:
0|FILE|ENV|p1|p2
1|CARD|PROD|GER|SW
1|CARD|DEV|GER|SW
1|CARD|PROD|GER|VP
9||22/10/2018|3
The record with 0 is header, 1 is the information and 9 is footer. I used the below code to read this file but it does not read the data correctly. I need to read the trailer for the information and use them but can drop header and trailer variables at the end. Could you please help:
DATA TEST;
INFILE File1 DLM="|" DSD ;
INPUT @1 RECORD_TYPE 1.;
IF RECORD_TYPE = 0 THEN DO;
CNT_HDR +1;
OUTPUT;
END;
ELSE IF RECORD_TYPE=9 THEN DO;
INPUT PROCESS_NAME :$4.
LOAD_DATE :DATE9.
NUMBER_OF_RECORDS :1.;
CNT_TLR+1;
OUTPUT;
END;
ELSE DO;
INPUT @2 SYSTEM :$4.
ENVIRONMENT :$4.
PORTFOLIO :$3.
SUBPORTFOLIO :$2.
TOT_CNT+1;
OUTPUT;
END;
RUN;
data test;
infile cards dlm="|" dsd;
input record_type @;
select (record_type);
when (0)do;
cnt_hdr + 1;
output;
end;
when (9) do;
input
process_name :$4.
load_date :ddmmyy10.
number_of_records
;
cnt_tlr + 1;
output;
end;
otherwise do;
input
system :$4.
environment :$4.
portfolio :$3.
subportfolio :$2.
;
tot_cnt + 1;
output;
end;
end;
format load_date ddmmyy10.;
cards;
0|FILE|ENV|p1|p2
1|CARD|PROD|GER|SW
1|CARD|DEV|GER|SW
1|CARD|PROD|GER|VP
9||22/10/2018|3
;
run;
Just read in the file as a pipe delimited file, then you will have a variable where you can do conditional logic to see if its 0 or 9? I can't actually read that code as its all in upper case, doesn't use a code window (its the {i} above post area), and has smileys in it and such like.
data test;
infile cards dlm="|" dsd;
input record_type @;
select (record_type);
when (0)do;
cnt_hdr + 1;
output;
end;
when (9) do;
input
process_name :$4.
load_date :ddmmyy10.
number_of_records
;
cnt_tlr + 1;
output;
end;
otherwise do;
input
system :$4.
environment :$4.
portfolio :$3.
subportfolio :$2.
;
tot_cnt + 1;
output;
end;
end;
format load_date ddmmyy10.;
cards;
0|FILE|ENV|p1|p2
1|CARD|PROD|GER|SW
1|CARD|DEV|GER|SW
1|CARD|PROD|GER|VP
9||22/10/2018|3
;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.