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

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

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

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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