BookmarkSubscribeRSS Feed
shl007
Obsidian | Level 7

Hi - I have some starter code below I'm trying to apply to add <root> and end </root> tags to a large XML file. Two questions:

1) is there a way to specify a DIFFERENT output file name?

2) Any ideas on how to get around a workspace “disconnected” error? Is there an alternate approach I can use to put  <root> and </root> tags in the file?

 

  data _null_;
     infile 'c:\output\temp.xml' end=eof;
    input;
      file "c:\output\temp1.xml";
         if _n_=1 then do;
        put "<root>";
        end;
            put _infile_;
         if eof then do;
       put "</root>";
   end;   
run;
5 REPLIES 5
shl007
Obsidian | Level 7
#1 - I answered my own question via the code; the output filename is already specified.
#2 - still TBD
ballardw
Super User

Anything involving "disconnected" is likely not related directly to your code.

Since the code provided works on a small file there is nothing wrong there. However you may need to consider LRECL for your actual file if it has real long "lines" (> 32767 ). This may happen if your xml has freeform text fields that contain extensive text.

 

Another approach might be to create two very small text files one with the "<root>" and the other  

"</root>". Then use a system tool to concatenate the 3 files.

 

I have to assume with your comment about "disconnected" that you are attempting to modify a file on a remote file system somewhere. It may be that you need to copy the file to a local location, run your code creating a local updated version and then upload the modified version back to the problematic location.

 

If that approach is not feasible then you have to diagnose conditions causing the disconnect which may be well out of the scope of many of us on this forum.

 

shl007
Obsidian | Level 7

I'm thinking some of the issue is the unstructured nature of my XML file, as far as using a data step to insert <root> and </root>. Instead of a system tool, I'm hopeful I can just import the separate files into separate datasets and concatenate them thru data step to get the <root> and </root> inserted at beginning and end of the file, respectively. Let me know if you can think of any pitfalls with this approach other than its lack of elegance ...

 

The wrinkle here is, I've modified the code to use a PIPE command. So I may be importing multiple files at once. This may be tricky (i.e., the <root> and </root> would need to be inserted for EACH file).

 

ballardw
Super User

Have you been to successfully just read in ONE of these files?

You say the issue is disconnecting. If you get disconnected from your data source I don't see how using an approach to read multiple of these files is going to make anything better?

ChrisNZ
Tourmaline | Level 20

To go around the timeout issue, you could run an OS command. Save the two extra lines and run:

copy header.txt+c:\output\temp.xml+footer.txt  c:\output\temp1.xml

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
  • 5 replies
  • 691 views
  • 0 likes
  • 3 in conversation