DATA Step, Macro, Functions and more

Proc Print fail for Obs starting with "<"

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Proc Print fail for Obs starting with "<"

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?


Accepted Solutions
Solution
‎08-16-2017 08:23 AM
Community Manager
Posts: 3,362

Re: Proc Print fail for Obs starting with "<"

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

 

View solution in original post


All Replies
Super User
Posts: 9,611

Re: Proc Print fail for Obs starting with "<"

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?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

Re: Proc Print fail for Obs starting with "<"

Posted in reply to KurtBremser

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

Super User
Posts: 9,611

Re: Proc Print fail for Obs starting with "<"

Did you copy/paste my code and run it, or run your original code with changes?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

Re: Proc Print fail for Obs starting with "<"

Posted in reply to KurtBremser
Yes, I run your code, copied and pasted.
SAS Super FREQ
Posts: 4,124

Re: Proc Print fail for Obs starting with "<"

[ Edited ]

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.

 

Community Manager
Posts: 3,362

Re: Proc Print fail for Obs starting with "<"

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

Super User
Posts: 9,611

Re: Proc Print fail for Obs starting with "<"


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎08-16-2017 08:23 AM
Community Manager
Posts: 3,362

Re: Proc Print fail for Obs starting with "<"

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

 

Super User
Posts: 9,611

Re: Proc Print fail for Obs starting with "<"

Posted in reply to ChrisHemedinger

Ha! That's why I always have "text" (listing) output activated in EG. Raw values stay as they are. And it's easier to post results into the {i} window here.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 27

Re: Proc Print fail for Obs starting with "<"

Posted in reply to KurtBremser

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 242 views
  • 10 likes
  • 5 in conversation