BookmarkSubscribeRSS Feed
Quartz | Level 8


I have over a 1000 EGP files and i want to change a minor thing in 1 particular program that is part of the EGP project. Every single one of them needs to be changed, so a 1000 changes.


I took the following steps so far :

1. Convert EGP to ZIP

2. Unzip the file


After action number 2. i have a project.XML file which I was hoping to import into SAS and then do the conversion and then output it again to XML, rezip it and then rename it to EGP.


However reading in this XML file gives an error message :


libname local "g:\mylocation";

LIBNAME xmlfile xmlv2 'g:\mylocation\project.xml' XMLTYPE=GENERIC;;

DATA local.project;

SET xmlfile.project;


ERROR: PCDATA content found outside column/table boundary. content is false.

ERROR: XML data is not in a format supported natively by the XML libname engine. Files of this type may require an XMLMap to be

input properly.


2 questions :

1. Is my method right ?

2. Why can't i read the XML file ?


Thanks for your help !!




Super User

I'd treat the XML as text (which it is) and use a data step with infile and file to manipulate it.


The next thing I'd do is to remove that program from the egp's and store it on the server to %include it from there. Then you need only one simple edit next time around.

Quartz | Level 8

Hi Kurt,

This sounds like a great idea, however when

- I treat is as txt

- then change something in the txt

- then rename it back to XML

- then zip the XML file

- then rename the zip file to an egp file


the EGP project won't open......


EG says : There was an error reading the project file. The format is invalid or not correct.


Now when i unpacked the EGP file, there was also a "result.txt" file. Should I also involve this one again ?




Quartz | Level 8

It's not because I forgot to re-include the result.txt file in the EGP, so I notice.


Something is wrong about this code. After renaming the XML extension to TXT i perform the following.

Apperently re-exporting this as TXT file and the renaming it to XML causes the XML file to be corrupt.


Not sure how to proceed now....


%macro changeprog (mysourcefolder, mysourceprog, olditem1, newitem1, olditem2, newitem2, mydestfile, mydestfolder);


data programds1;

infile "&mysourcefolder.\&mysourceprog." dlm = ';';

length progtext $ 30000 ;


input progtext;


data programds2;

set programds1;

progtext = tranwrd(progtext,"&olditem1.","&newitem1.");

progtext = tranwrd(progtext,"&olditem2.","&newitem2.");



%let newdir = %sysfunc(dcreate(&datum ,&mydestfolder.\));

%let filename= "&mydestfolder.\&datum.\&mydestfile..txt";


data _null_;

file &filename.;


set work.programds2;

put (progtext) (+(-1));





Super User

Disclaimer: I have no clue about the "real" structure of a .egp file. I know I can unzip it and get its contents, if a problem arises. I've never built one "manually".


One guess would be that you need to alter another piece of information in the whole archive for it to work.

Or you need to use one special compression method only so that EG recognizes the file correctly.


Since we keep no production programs in EG projects, but have all code in .sas files in the versioning system, similar problems don't arise here. I only unzip projects if they were corrupted during storing and we need to retrieve as much as we can for the end-user.

Quartz | Level 8

The solution lies in how to read a txt file keeping every single line in a dataset record.


For instance if I have this :


  &lt;Assembly /&gt;
  &lt;Factory /&gt;


How to make sure that read them into a dataset containing 10 records ?


At the moment I'm not reading correctly. This line :

<?xml version="1.0" encoding="utf-16"?>


is converted to



Can't figure out why..




Super User

The simplest way to catch the whole input line is this:

data want;
infile "have.xml";
length line $100;
line = _infile_;

Adjust length and a lrecl= infile option if needed.

Quartz | Level 8

Hi Kurt,

Thanks for this ! This code is reading into the sas dataset with the blanks included, which is good !


What if I changed some code in the resulting SAS dataset and then re-export it as a txt file.

How would i get the blanks again in the TXT file ? I presume this is what is blocking the opening of the XML file.

I'm getting everything left aligned.........


No luck with this :

data _null_;

file &filename.;

 set work.programds2;

put (progtext) (+(-1));







Super User

I'd tackle this problem in two steps:


First, make a manual change to the XML and see if the manual change (done with the Windows Editor) is accepted by EG after re-zipping.

Only when you know how to do it manually and that it works, you can start to automate things. The manual method also lets you test what needs to be preserved (like trailing blanks or similar).


Then, look for a tool that accomplishes the automated change. On UNIX I'd try to unzip, run awk on the XML in question, and then re-zip. UNIX tools are always good for scripting and automating. SAS might not be the right tool in the end.

Lapis Lazuli | Level 10

Use SAS XML mapper to create a mapper file for your XML. It is clear from the log your XML file is not in standard XML format


filename xml_lib "/path/filename.xml";
filename MAP "/mapfile_path/";

libname xml_lib xmlv2 xmlmap=MAP;   /*Creates the XML library*/

option replace;

proc copy in=xml_lib out=work memtype=data;   /*Copies all XML tables to work*/

Now use SQL join or Data step Merge to create your final table from the downloaded tables in PROC COPY.


Or You can Create a Single mapper using replace functionality to create your data set without any additional join.


Same mapper can be then used to create your output XML file after manipulation.




Let us know if it helped. 


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!

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
  • 9 replies
  • 3 in conversation