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?
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;
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?
Thank you KurtBremser,
Very weird, in my case the result is the folllowing:
Did you copy/paste my code and run it, or run your original code with changes?
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.
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;
@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.
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;
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.
for what it is worth, i was able to run your code KurtBremser successfuly.
i executed the code in SAS 9.4M4 from EnterpriseGuide 7.13HF5
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.