BookmarkSubscribeRSS Feed
Faruk
Obsidian | Level 7

Hi,

We have over 2000 sas codes. What i want to do is like a text editor (example: ultraedit or pspad). Search in a directory where the sas files are, and search for a text (example rsubmit;) and delete this line and search further. And save the file.

I want to do this in a sas file. So i can run it every time for all sas code.

So just search an replace for files in a folder.

Is this possilbe and how?

Thanks.

Faruk

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I too would be interested in hearing if there is software designed to do this.

At the time, I wound up writing SAS code to do search and replace inside of *.sas files in a directory(s), and I must say it usually worked, but there were a few problems that I never anticipated and never figured out why they were happening.

--
Paige Miller
ballardw
Super User

Are you 100 percent sure that deleting the line will be sufficient?

I know that I often break single logical lines across physical lines when they are long. The lines, in my case are often complex table statements in proc tabulate, variable lists in array declarations, parameters for multiple parameter macros, ods or graphics options.

It could be that removing a single physical line would yield unworkable code, or at least that would yield unexpected results.

I suspect that your first step would be a reformatter that would create single physical lines to match the logical lines. After you get this it should be relatively easy. Comments in your code may make this a tad harder because of potential length of comment sections and different coding styles such as

/*  a very long comment spanning several lines with

   one ending comment indicator like this

*/

and the

/* every line is commented separately like this */

* or the occasional line commented like this;

and the macro commenting .

Should comments involving your search term be removed?? Especially since they could contain other critical information.

Also, are you looking to replace the original file leaving no trace of your starting condition (probably a bad idea) or to copy the source to a safe location and then rewrite the modified code to the original location?

Faruk
Obsidian | Level 7

Hi,

Sometimes i want to delete a line and sometimes not. This depent to a text that i want to remove.

I just want to know how i can do this in sas. So that i also search for comment etcetera.

I dont want to replace the original file, i want to save it to another directorie where i promote the sas codes.

Faruk
Obsidian | Level 7

This is the macro that i have in ultraedit. I want the same in sas.

/*Gencodeconvert*/
InsertMode                                                                                                                                                                                                  
ColumnModeOff                                                                                                                                                                                               
HexOff                                                                                                                                                                                                      
UnixMacToDos                                                                                                                                                                                                
UltraEditReOn                                                                                                                                                                                               
Top                                                                                                                                                                                                         
Find "/*****************************************************************************************/                                                                                                           
/* end of proloog                                                                        */                                                                                                                 
/*****************************************************************************************/"                                                                                                                
IfFound                                                                                                                                                                                                     
StartSelect                                                                                                                                                                                                 
SelectToTop                                                                                                                                                                                                 
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
EndSelect                                                                                                                                                                                                   
Delete                                                                                                                                                                                                      
Top                                                                                                                                                                                                         
StartSelect                                                                                                                                                                                                 
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
Key DOWN ARROW                                                                                                                                                                                              
EndSelect                                                                                                                                                                                                   
Delete                                                                                                                                                                                                      
EndIf                                                                                                                                                                                                       
Find "/*****************************************************************************************/                                                                                                           
/* end of proloog                                                                        */                                                                                                                 
/*****************************************************************************************/"                                                                                                                
IfFound                                                                                                                                                                                                     
Delete                                                                                                                                                                                                      
EndIf                                                                                                                                                                                                       
Top                                                                                                                                                                                                         
UltraEditReOn                                                                                                                                                                                               
Find "/************************************************************/                                                                                                                                        
/* Job section:  TRACKING EPILOG  */                                                                                                                                                                        
/* Origination:  source.source.epiloog.source  */"                                                                                                                                                          
IfFound                                                                                                                                                                                                     
SelectToBottom                                                                                                                                                                                              
Delete                                                                                                                                                                                                      
EndIf                                                                                                                                                                                                       
PerlReOn                                                                                                                                                                                                    
Top                                                                                                                                                                                                         
Loop 0                                                                                                                                                                                                      
IfEof                                                                                                                                                                                                       
ExitLoop                                                                                                                                                                                                    
Else                                                                                                                                                                                                        
Find RegExp "(endrsubmit|rsubmit|%syslput|%sysrput|%let mainserv|options comamid=tcp|signon mainserv|%let syslast=|/* Name: |access the data for this step|execute the process for this step|/* generated: )"
IfFound                                                                                                                                                                                                     
DeleteLine                                                                                                                                                                                                  
Else                                                                                                                                                                                                        
ExitLoop                                                                                                                                                                                                    
EndIf                                                                                                                                                                                                       
EndIf                                                                                                                                                                                                       
EndLoop                                                                                                                                                                                                     
Top                                                                                                                                                                                                         
Loop 0                                                                                                                                                                                                      
IfEof                                                                                                                                                                                                       
ExitLoop                                                                                                                                                                                                    
Else                                                                                                                                                                                                        
Find "/************************************************************/"                                                                                                                                       
IfFound                                                                                                                                                                                                     
DeleteLine                                                                                                                                                                                                  
Else                                                                                                                                                                                                        
ExitLoop                                                                                                                                                                                                    
EndIf                                                                                                                                                                                                       
EndIf                                                                                                                                                                                                       
EndIf                                                                                                                                                                                                       
EndLoop                                                                                                                                                                                                     
TrimTrailingSpaces                                                                                                                                                                                          
Save                                                                                                                                                                                                        
CloseFile                                                                                                                                                                                                   

/*Macroconvert */
IsertMode                                         
ColumnModeOff                                      
HexOff                                             
UnixMacToDos                                       
TrimTrailingSpaces                                 
Top                                                
PerlReOn                                           
Loop 0                                             
IfEof                                              
ExitLoop                                           
Else                                               
Find RegExp "(endrsubmit|rsubmit|%syslput|%sysrput)"
IfFound                                            
DeleteLine                                         
Else                                               
ExitLoop                                           
EndIf                                              
EndIf                                              
EndLoop                                                                     
Save                                               
CloseFile   

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 909 views
  • 0 likes
  • 3 in conversation