BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathasivam
Fluorite | Level 6

Hi everyone,

 

In SAS I have a dataset and I need to export that an XML file in UTF-8 encoding. In a particular field, there is a long string with special characters which is getting truncated while exporting to XML. There are other values which has more characters are exported without any issue. But the particular field with issue has more special characters. Requesting your help to get it resolved

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You seem to be showing a macro that generates PART of a data step.

To know why values might be truncated you need to see the full data step that is being run.  And the definition of any input data it is reading.

For example your macro is generating this code:

Field_Special = HTMLENCODE(&Field_ID.);
put '<answer>' Field_Special +(-1) '</answer>';

What is the length defined for the variable FIELD_SPECIAL?

What is the value of the macro variable FIELD_ID?  If it is the NAME of a variable then what is the length defined for that variable.

 

To be extra careful you might try defining FIELD_SPECIAL to be longer.  The maximum length for a character variable is 32767 bytes.  So try adding this line to the top of the data step where you are going to run the code generated by calling that macro.

length FIELD_SPECIAL $32767 ;

View solution in original post

4 REPLIES 4
Sajid01
Meteorite | Level 14

Hello
Can you share sample data and the code you are using?
Make sure the data includes good and bad fields and should be as a data step.

sathasivam
Fluorite | Level 6
Hello, Thanks for the response

Value from Dataset:
8822: yhrtahdjdidodjdhsgs 'Gebeew: Harash 2 & 3'Met outgrguytf rocket 'Gebeew: Harash 8 & 9' ward tyehtdhctsf or luhuh edf oea doo Rankedd DOublueh OH abëpogf tyfjjfb.Ir ravel doubl ufhjfnbf kj uhtdgc poyhgdb or do siyufjdkhvnfbg khhff onto ereikendheid

Value in XML:

8822: yhrtahdjdidodjdhsgs 'Gebeew: Harash 2 &amp; 3'Met outgrguytf rocket 'Gebeew: Harash 8 &amp; 9' ward tyehtdhctsf or luhuh edf oea doo Rankedd DOublueh OH abëpogf tyfjjfb.Ir ravel doubl ufhjfnbf

Truncated portion:

kj uhtdgc poyhgdb or do siyufjdkhvnfbg khhff onto ereikendheid

XML map used:

%macro file_loop(Field_ID);
if &Field_ID. not in('.',' ') then Do;
if indexc(&Field_ID.,'&%<>') = 0 then do;
put '<question>';
put '<answer>' &Field_ID. +(-1) '</answer>';
put '</question>';
End;
else Do;
put '<question>';
Field_Special = HTMLENCODE(&Field_ID.);
put '<answer>' Field_Special +(-1) '</answer>';
put '</question>';
end;
End;
else Do;
put '<question>';
put '<answer/>';
put '</question>';
end;
%mend file_loop;

Another query is, in data set there is an "&" symbol which is printed as "&amp;" in XML, please help with the same, Thanks in advance
Tom
Super User Tom
Super User

You seem to be showing a macro that generates PART of a data step.

To know why values might be truncated you need to see the full data step that is being run.  And the definition of any input data it is reading.

For example your macro is generating this code:

Field_Special = HTMLENCODE(&Field_ID.);
put '<answer>' Field_Special +(-1) '</answer>';

What is the length defined for the variable FIELD_SPECIAL?

What is the value of the macro variable FIELD_ID?  If it is the NAME of a variable then what is the length defined for that variable.

 

To be extra careful you might try defining FIELD_SPECIAL to be longer.  The maximum length for a character variable is 32767 bytes.  So try adding this line to the top of the data step where you are going to run the code generated by calling that macro.

length FIELD_SPECIAL $32767 ;
sathasivam
Fluorite | Level 6
Hi Tom,

Declared length FIELD_SPECIAL $32767 ; in datastep and it is working as expected

Thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 616 views
  • 0 likes
  • 3 in conversation