DATA Step, Macro, Functions and more

Comparing two SAS Programs

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Comparing two SAS Programs

Dear Experts,

Is there any way to compare two SAS programs programatically. One way I know is to compare through TextPad but that is more of manually.

Br, Amit


Accepted Solutions
Solution
‎07-02-2015 05:22 AM
Super User
Posts: 7,762

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

In UNIX, use the diff (diff utility - Wikipedia, the free encyclopedia) command. It was specifically written for this purpose.

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

View solution in original post


All Replies
Super User
Super User
Posts: 7,942

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

Yes, just datastep load them into datasets, then proc compare:

data base;

     length buffer $2000;

     infile "xyz.sas";

     input buffer $;

run;

...

proc compare base=base...;

run;

However, more importantly is why you want to do this.  Computer comparisons are logical, hence if there is one extra line in at line 2, then everything from that point on will not match. 

I would suggest that you are better off using version control software - its useful at any level of programming.  This is a database which holds base file and every revision to that file.  It can give you XML reports on differences etc.  Also has roll-back functionality and never loses history.

Contributor
Posts: 21

Re: Comparing two SAS Programs

The reason of comparing program is that I need to migrate some SAS programs from SDD3.5(windows) to SDD4.5(unix). And due to this I have to make same changes in the program like changes backward slash ('\') to forward slash ('/'). After making changes I need to make sure that anything else is not changed accidently.

Br,Amit

Super User
Super User
Posts: 7,942

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

Well, you can use the compare above, but your better off using a text compare such as diff which KurtBremser has provided.  You can then use that output as part of the documentation of the migration program.

Solution
‎07-02-2015 05:22 AM
Super User
Posts: 7,762

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

In UNIX, use the diff (diff utility - Wikipedia, the free encyclopedia) command. It was specifically written for this purpose.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,020

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

There are a couple of tools to compare two file . Like  WinMerge

Contributor
Posts: 22

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

Also useful is the freely available tkdiff that gives a visual, side by side comparison of programs (Unix). On a Windows platform, the PSP editor has a very similar text difference tool that does a side by side comparison.

Super Contributor
Super Contributor
Posts: 3,174

Re: Comparing two SAS Programs

Posted in reply to AmitRathore

The idea of comparing two SAS programs as-is could be flawed, depending on the SAS environment where invoked, and also considering if/how SAS AUTOCALL MACROs or MACRO statements (old SAS 79 style - ex:  MACRO _BOO  BLAH BLAH BLAH % ) may be exploited (that being embedded code references where you would only see %xxxxxxx;  (disclaimer-invoked: oversimplified example) in the main SAS code-piece being analyzed.

Also depending on the SAS process / code complexity, there may be path-conditions influencing just how much of the code is executed, such as a passed SYSPARM or incoming %LET macro variables.

Scott Barry

SBBWorks, Inc.

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 1106 views
  • 7 likes
  • 6 in conversation