BookmarkSubscribeRSS Feed
proc_talk
Fluorite | Level 6

This previous post explains my situation very well, but I don't feel it's been fully answered.

https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-Enterprise-Guide-Replace-All-File-Path-Links... 

AlanC's reply mentions that there is a way to read in an .egp file through a zip library, manipulate the XML data within the file to change the file path references of the contained .sas programs, and then to re-zip and export the .egp file, but that is not nearly specific enough for me to follow. Can anyone describe this process in more detail and potentially provide a good template with reusability for the XML procedure part?

 

For more background, I imagine this procedure (changing all file paths) may become a common procedure for me because of using different branches in GitLab to test out enhancements to existing code. I've copied the production .egp file that references the main branch/production .sas files and now I want to repoint the copy of the .egp to the new branch copies of the main branch/production .sas files that are stored in a separate folder to begin working on the enhancement. Basically I'm attempting not to disturb the production code/.egp files while setting myself up an area to mess with code.

6 REPLIES 6
AlanC
Barite | Level 11

I am happy to be more specific. First off, I understand it can be difficult to get started not knowing the first step so I can help with that. A couple of questions, have you worked with C# or PowerShell? Even Python would probably be ok. But let's get a baseline on tech. Are you a programmer or an analyst? Have you worked with xpath by any chance?

 

To help, take one of your egp files and just change the extension to zip and look at the contents.  

 

I can even write the code for you since I have a small amount of free time. If you have an egp file, save it where I can get it and tell me what change you want. I will code in C# but you can follow along. Once complete, I can place it in github for others.

 

You can do this in SAS as well. I will lay out a flow and someone else can handle the SAS code. Since I don't have access to SAS, I can't test so no need to try.

https://github.com/savian-net
proc_talk
Fluorite | Level 6

Oh great! Thank you, AlanC! Didn't expect to get you back immediately like that!

 

I have used Python before, but using it through my company device is more complicated than it really should be and would be inconvenient. That said, I don't have experience with the three other programming tools you mentioned (C#, PowerShell, xpath), however, I do have PowerShell on my machine so we could maybe go that route. The SAS-native flow would probably be the ideal solution. I'm used to programming in SAS/SQL and have done some VBA coding, but manipulating metadata like this is pretty uncharted territory for me. I mainly do ETL type of tasks and analysis.

 

I was able to change the extension of an .epg file to .zip and view the included XML file in Notepad. I see several lines in there that seem to be the ones of interest that look like this:

<FullPath>V:\directory1\subdirectory1\subdirectory2\subdirectory4\subdirectory5\my_program_name1.sas</FullPath>

In my case, I'd like to basically swap [subdirectory5]'s value to a directory adjacent to the current one while maintaining the other directory names and program names. I'll need to do this for approximately 30 programs. Maybe just performing a manual find/replace and resaving the XML file and switching the extension back to .egp is a good enough solution for me honestly. I'll see if that works and report back.

 

Unfortunately, I'm not sure I can share the entire .epg file explicitly since it's a confidential work asset, but I can try to share as much as I can in a general sense as needed. Sorry for the extra layer of inconvenience there.

AlanC
Barite | Level 11

I never expected the whole file, just an example works which is what you have provided. SAS is not the best tool for this kind of work, IMO. You have C# and XPath on your machine as well since they are required for Windows to run.

 

Let me code up a C# program that does this, command line, and then you can modify to your heart's content in VS Code. Doing it manually is just a PITA and I can use a break from MS Office coding (VSTO).   I have parts of it already so not a big deal.

https://github.com/savian-net
proc_talk
Fluorite | Level 6

So hopefully you haven't gone too far down the rabbit hole on my behalf coding something up because this process does exactly what I need it to with minimal manual intervention:

  1. Switch .egp extension to .zip
  2. Examine the XML file in the .zip folder
  3. Perform a find/replace on the current file path with the new file path
  4. Save the XML file and .zip file
  5. Switch the extension back to .egp
  6. Verify that the file paths have updated after opening the .egp

Thank you for the help! I thought it was going to be much more complicated than just a find/replace. They really should build that into EG as a feature!

AlanC
Barite | Level 11

I have not. Had to get stuff wrapped up for my client.

 

Sounds like you have a plan. There may be open source software that does this already so search for that. Anything that can examine zip files should recognize it as a zip in the header. A number of companies use this technique including all Office products (ex. docx, xlsx, pptx, etc.). There are a number of commercial products, for Office, that handle their zips such as GemBox. My guess is there are general programs that can handle egp such as Directory Opus.

 

You can script something up without too much trouble using PowerShell. Download PowerShell IDE (it may be on your machine). VS Code is also a useful editor for PowerShell. That can save you some time. 

 

Glad it worked out for you.  Ping me if you have any questions. 

https://github.com/savian-net
Patrick
Opal | Level 21

You could also investigate what the EG migration wizard could do for you - especially when used with a pre-generated mapping file.

Migrate SAS Content with the Migration Wizard

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 943 views
  • 1 like
  • 3 in conversation