Help using Base SAS procedures

Issue writing data to output file.

Reply
Occasional Contributor
Posts: 18

Issue writing data to output file.

Hi All,

I am having issue when writing the data into mainframe file.

when I print DATA01, I see no issues. but when I write to output file I get completely different data (not as expected).

The record length is approximately 1200.

can someone please help me.

Best Regards,

DATA _NULL_;                                                      
  FILE OUTFL1 NOPRINT NOTITLES       ;                        
  FORMAT VAR1   VAR2 VAR3 VAR4 VAR5 VAR6       $050     
     VAR7   VAR8 VAR9 VAR10 VAR11 VAR12    $100     
     ;                                                        
  SET TOLIST ;                                                    
  IF _N_ = 1 THEN                                                 

  PUT @001 'VAR1,VAR2,VAR3,VAR4,VAR5,VAR6,VAR7,VAR8,VAR9,VAR10,VAR11,' 

  @058 'VAR12,' ;                                             
  PUT @001 VAR1        $050. '","'                            
  @053 VAR2        $050. '","'  

.

.

.

.

.                         
                                                                  

  ;   

Occasional Contributor
Posts: 18

Re: Issue writing data to output file.

Hi All,

I resolved the issue by using DLM = ',' DSD option in FILE Statement

But I could not find why PUT was writing incorrect/wired values to output.

DATA _NULL_;                                                      
  FILE OUTFL1 NOPRINT NOTITLES  DLM = ',' DSD     ;                        
  FORMAT VAR1   VAR2VAR3VAR4 VAR5 VAR6       $050     
     VAR7   VAR8VAR9VAR10 VAR11 VAR12    $100     
     ;                                                        
  SET TOLIST ;                                                    
  IF _N_ = 1 THEN                                                 

  PUT @001 VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 VAR9 VAR10 VAR11 ;

Super User
Super User
Posts: 7,078

Re: Issue writing data to output file.

Why do you have a FORMAT Statement in this DATA _NULL_ step that is just assigning generic $ formats to variables? 

Perhaps you meant to use a LENGTH statement?  But even then for this data step since you are not modifying the data why would you need to change the length from what it has on input data set.

Trusted Advisor
Posts: 2,116

Re: Issue writing data to output file.

Hi,

Please just post a question once to the forums.

The first thing that I noticed is that your format statement is incorrectly formatted.  The FORMATs require a period (".") at the end (e.g. "$050.").  You have it correct in you PUT statement.

I am concerned that putting the NOPRINT and NOTITLES options on a non-print device may confuse the system.  Try removing them.

Can you provide an example of the input data and the correct and incorrect output.

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