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

Dear Sas community,

 

I could not find the solution for the following problem.

For the following table, the Proc Print procedure fails to correctly assing the value of the OBs starting with symbol "<"

/* First part */

data test;
input n1 :$20. n2 :$100. ;
datalines;
1 AA
221 <AA>
441 A<A>
;run;

/* First part works correctly, but the following Proc Print fails to print Obs "<AA> */

 

proc print data=test2;
var n1 n2;
run;

 

What could be a problem?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

The problem is that you are using HTML output, and the value is interpreted as an HTML tag.  If you output to LISTING or PDF or RTF, you'll see the values.

 

data test;
input n1 :$20. n2 :$100.;
encoded = htmlencode(n2);
encoded2 = urlencode(trim(n2));
datalines;
1 AA
221 <AA>
441 A<A>
;
run;

proc print data=test ;
var n1 n2 encoded encoded2;
run;

html.png

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

10 REPLIES 10
Kurt_Bremser
Super User

I see no problem:

data test;
input n1 :$20. n2 :$100.;
datalines;
1 AA
221 <AA>
441 A<A>
;
run;

proc print data=test;
var n1 n2;
run;

Result:

Beob.    n1      n2

  1      1      AA  
  2      221    <AA>
  3      441    A<A>

Note that all values show as they were set in the first data step.

Could it be that your problem comes from the fact that you create dataset test, but print dataset test2?

sburnos
Fluorite | Level 6

Thank you KurtBremser,

 

Very weird, in my case the result is the folllowing:

2017-08-16 13_51_06-SAS - [Results Viewer - SAS Output].png

sburnos
Fluorite | Level 6
Yes, I run your code, copied and pasted.
Rick_SAS
SAS Super FREQ

I suspect the OP is using the HTML destination, which is somehow interpreting '<A'  as the beginning of an HTML tag.

I can reproduce what the OP sees when I use the ODS HTML destination, but other destinations such as LISTING and RTF print the data correctly.

 

ChrisHemedinger
Community Manager

Interpreting the HTML code is desired behavior, and is by design.  It allows us to create active reports like this:

 

data test;
infile datalines dsd delimiter=',';
input n1 :$20. n2 :$100.;
encoded = htmlencode(n2);
encoded2 = urlencode(trim(n2));
datalines;
1, AA
221, <AA>
221, <A href="http:/communities.sas.com">ALL the answers</a>
441, A<A>
;
run;

proc print data=test ;
var n1 n2 encoded encoded2;
run;

htmlrep.png

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Kurt_Bremser
Super User

@Rick_SAS wrote:

I suspect the OP is using the HTML destination, which is somehow interpreting '<A'  as the beginning of an HTML tag.

I can reproduce what the OP sees when I use the ODS HTML destination, but other destinations such as LISTING and RTF print the data correctly.

 


I tested a simple webpage with <AA> embedded in it. PaleMoon, Firefox and IE all interpret it as an "unknown tag" and show nothing. That is standard-conforming behaviour, IMO.

ChrisHemedinger
Community Manager

The problem is that you are using HTML output, and the value is interpreted as an HTML tag.  If you output to LISTING or PDF or RTF, you'll see the values.

 

data test;
input n1 :$20. n2 :$100.;
encoded = htmlencode(n2);
encoded2 = urlencode(trim(n2));
datalines;
1 AA
221 <AA>
441 A<A>
;
run;

proc print data=test ;
var n1 n2 encoded encoded2;
run;

html.png

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
utrocketeng
Quartz | Level 8

for what it is worth, i was able to run your code KurtBremser successfuly.  

image.png

 

i executed the code in SAS 9.4M4 from EnterpriseGuide 7.13HF5

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
  • 10 replies
  • 1197 views
  • 10 likes
  • 5 in conversation