DATA Step, Macro, Functions and more

exporting 3 datasets into one fixed width text file

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

exporting 3 datasets into one fixed width text file

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


Accepted Solutions
Solution
‎11-20-2014 01:25 AM
Super User
Posts: 7,758

Re: exporting 3 datasets into one fixed width text file

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 11,343

Re: exporting 3 datasets into one fixed width text file

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;

Contributor
Posts: 25

Re: exporting 3 datasets into one fixed width text file

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.

Super User
Posts: 11,343

Re: exporting 3 datasets into one fixed width text file

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.

Contributor
Posts: 25

Re: exporting 3 datasets into one fixed width text file

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.

Solution
‎11-20-2014 01:25 AM
Super User
Posts: 7,758

Re: exporting 3 datasets into one fixed width text file

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 25

Re: exporting 3 datasets into one fixed width text file

Posted in reply to KurtBremser

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.

Super User
Posts: 10,018

Re: exporting 3 datasets into one fixed width text file

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

Contributor
Posts: 25

Re: exporting 3 datasets into one fixed width text file

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 1950 views
  • 0 likes
  • 4 in conversation