BookmarkSubscribeRSS Feed
JS
Obsidian | Level 7 JS
Obsidian | Level 7

I want to be able to see if the types of data we are sending changes over time.

 

I have a series of records with a range of namespaces that are sent.

 

Have

Record XMLData

1 <keyData siteId="1" id="" lastName="Caser" />

2 <keyData siteId="1" email="do_08@awef.com" />

...

 

Want

Record Type

1 ID

1 lastName

2 ID

2 email

 

Sometimes I'll have ID, sometimes I'll have ID, Email, and SSN -- it varies by the record.

 

Does anyone have experience trying to shred out XML using SAS?

4 REPLIES 4
Ksharp
Super User
Post some more data or example XML file would be better .


Ksharp
Super User


data have;
input Record XMLData $50.;
cards;
1 
2 
;
run;

data want;
 set have;
 pid=prxparse('/\w+(?==")/o');
 s=1;e=length(xmldata);
 call prxnext(pid,s,e,xmldata,p,l);
 do while(p gt 0);
  type=substr(xmldata,p,l);output;
  call prxnext(pid,s,e,xmldata,p,l);
 end;
 drop pid s e p l;
run;


mkeintz
PROC Star

In your example each line is a set of space-separated words.  The last word of each is "/>" and you apparently want a part of the next-to-last word, namely the part to the left of the = sign.  You also want an output record with type='ID' for each incoming record number, regardless of content.

 

This code is not "xml-aware" in any way, but it does the particular task as you have described it:

 

data want (keep=record type);
  input record xmltext &$80.;
  length type $20;

  type='ID'; output;

  next_to_last_word=scan(xmltext,-2,' ');
  type=scan(next_to_last_word,1,'=');
  output;
datalines;
1 <keyData siteId="1" id="" lastName="Caser" />
2 <keyData siteId="1" email="do_08@awef.com" />
run;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 695 views
  • 0 likes
  • 4 in conversation