BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DanD999
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

8 REPLIES 8
ballardw
Super User

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;

DanD999
Quartz | Level 8

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.

ballardw
Super User

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.

DanD999
Quartz | Level 8

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.

Kurt_Bremser
Super User

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.

DanD999
Quartz | Level 8

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.

Ksharp
Super User

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

DanD999
Quartz | Level 8

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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