I have 3 datasets with different formats that I need to export into one file. There is a one line header dataset, a multiple line detail dataset and a one line trailer dataset. The record length is the same for each. I can export them individually with the code below but I need to put them in one file. Is this possible?
data _null_;
set header1 ;
file &TxtOut1. RECFM=F lrecl=173;
PUT
@1 seq_nbr
@7 record_type
@10 vendor_name
@40 client_name
@70 Carrier
@79 date_time
@105 filler
;
run;
/*Export fixed length data*/
data _null_;
set enrolled2 ;
file &TxtOut1. RECFM=F lrecl=173;
PUT
@1 Carrier
@10 DOB
@18 GPI
@32 PA_Type
@34 Effective_Date
@42 Expiration_Date
@50 Brand_Generic_Indicator
@51 Status_Code_Indicator
@52 External_Beneficiary_ID
@72 Client_Hierarchy_1
@87 Client_Hierarchy_2
@102 Campaign_ID
@110 Platform_Identifier
@112 Internal_External_Indicator
@113 Claim_ID
@133 Patient_First_Name
@153 Patient_Last_Name
@173 Patient_Gender
;
run;
data _null_;
set trailer;
file &TxtOut1. RECFM=F lrecl=173;
PUT
@1 seq_nbr
@7 record_type
@10 record_count
@19 filler
;
run;
Thanks
That is what happens with recfm=f, because recfm=f omits any end-of-line character(s). Actually, you have exactly one "line" with linelength=filesize, the 4097 is just an artifact of the viewer/editor. If you want to have fixed record length, but readable records, specify recfm=v lrecl=xxx and use formatted output (what you already do), so that you get fixed-width columns and the format lengths add up to lrecl.
data _null_;
set
header (in=in1)
enrolled2 (in=in2)
trailer (in=in3);
file &TxtOut1. RECFM=F lrecl=173;
if in1 then do;
PUT
@1 seq_nbr
@7 record_type
@10 vendor_name
@40 client_name
@70 Carrier
@79 date_time
@105 filler
;
end;
else if in2 then do;
PUT
@1 Carrier
@10 DOB
@18 GPI
@32 PA_Type
@34 Effective_Date
@42 Expiration_Date
@50 Brand_Generic_Indicator
@51 Status_Code_Indicator
@52 External_Beneficiary_ID
@72 Client_Hierarchy_1
@87 Client_Hierarchy_2
@102 Campaign_ID
@110 Platform_Identifier
@112 Internal_External_Indicator
@113 Claim_ID
@133 Patient_First_Name
@153 Patient_Last_Name
@173 Patient_Gender
;
end;
else if in3 then do;
PUT
@1 seq_nbr
@7 record_type
@10 record_count
@19 filler
;
end;
run;
Thanks for the quick reply. It's not honoring the record length. Everything is on 2 rows. The first row is 4097 characters wide. It's like there nees to be a return after each row.
Generally PUT ends each line with appropriate end of line character(s). Is there any chance that SAS is running under UNIX and you are looking at the results in Windows?
Or if you are getting any data from the enrolled2 data set on the same line check for an extra @ symbol that may be holding the data pointer.
I am using a Unix server and using SAS EG on my laptop. If I run it in batch mode on the server do you think it would work? I'll try it in the morning. Thanks.
That is what happens with recfm=f, because recfm=f omits any end-of-line character(s). Actually, you have exactly one "line" with linelength=filesize, the 4097 is just an artifact of the viewer/editor. If you want to have fixed record length, but readable records, specify recfm=v lrecl=xxx and use formatted output (what you already do), so that you get fixed-width columns and the format lengths add up to lrecl.
KurtBremser wrote:
That is what happens with recfm=f, because recfm=f omits any end-of-line character(s). Actually, you have exactly one "line" with linelength=filesize, the 4097 is just an artifact of the viewer/editor. If you want to have fixed record length, but readable records, specify recfm=v lrecl=xxx and use formatted output (what you already do), so that you get fixed-width columns and the format lengths add up to lrecl.
This worked. Thanks so much Kurt.
For the next two data step , add MOD option to append it at the end of the same file .
data _null_;
set enrolled2 ;
file &TxtOut1. RECFM=F lrecl=173 mod ;
PUT
data _null_;
set enrolled3 ;
file &TxtOut1. RECFM=F lrecl=173 mod ;
PUT
Xia Keshan
xia keshan wrote:
For the next two data step , add MOD option to append it at the end of the same file .
data _null_;
set enrolled2 ;
file &TxtOut1. RECFM=F lrecl=173 mod ;
PUT
data _null_;
set enrolled3 ;
file &TxtOut1. RECFM=F lrecl=173 mod ;
PUT
Xia Keshan
I tried it like this but it didn't work. I still get only 3 long lines.
data _null_;
set header1 ;
file &TxtOut1. RECFM=F lrecl=173;
PUT
@1 seq_nbr
@7 record_type
@10 vendor_name
@40 client_name
@70 Carrier
@79 date_time
@105 filler
;
run;
/*Export fixed length data*/
data _null_;
set enrolled2 ;
file &TxtOut1. RECFM=F lrecl=173 mod;
PUT
@1 Carrier
@10 DOB
@18 GPI
@32 PA_Type
@34 Effective_Date
@42 Expiration_Date
@50 Brand_Generic_Indicator
@51 Status_Code_Indicator
@52 MemberID
@72 Client_Hierarchy_1
@87 Client_Hierarchy_2
@102 Campaign_ID
@110 Platform_Identifier
@112 Internal_External_Indicator
@113 Claim_ID
@133 Patient_First_Name
@153 Patient_Last_Name
@173 Patient_Gender
;
run;
data _null_;
set trailer;
file &TxtOut1. RECFM=F lrecl=173 mod;
PUT
@1 seq_nbr
@7 record_type
@10 record_count
@19 filler
;
run;
Thanks.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.