i have a left-justified matrix of character labels that i want to right-justify for display.
there is an example in the SAS Help Center for the PUTC function that i have modified to teach myself:
data test;
length a b $ 6 ;
/* 123456 */
a = 'abc ' ;
b = put( a, $6. -R ) ;
put 'a=' a $6. ' b=' b $6. ;
c = right( a ) ;
put 'a=' a $6. ' c=' c $6. ;
run;
and it returns the results correctly:
note that put() is not defined:
ERROR: Invocation of unresolved module PUT.
no right-justification has been performed. where is my error? how can i achieve my goal?
TIA,
Ross Bettinger
When you use the HTML output destination, you can't use the PRINT statement (or PROC PRINT) to determine whether strings have multiple blanks because the HTML renderer "eats" extra blanks.
The last line of your IML program is correct. You can use the RIGHT function (and most other Base SAS functions) in SAS/IML. As you point out, PUT is on the list of exceptions.
The best way to verify that the spaces are really present is to translate them to some character (such as '*') that can be printed and counted. Here is how to use PROC PRINT for your example and how to use the PRINT statement in IML for your second example:
data test;
length a b $ 6 ;
/* 123456 */
a = 'abc ' ;
b = put( a, $6. -R ) ;
put 'a=' a $6. ' b=' b $6. ;
c = right( a ) ;
put 'a=' a $6. ' c=' c $6. ;
run;
/* note that the blanks do not appear when you display them in HTML */
proc print data=test;run;
/* however, you can replace blanks another character to see that they are there */
data test2;
set test;
array X[*] _CHARACTER_;
do i = 1 to dim(X);
X[i] = translate(X[i], '*', ' ');
end;
drop i;
run;
proc iml ;
a={ 'a ', 'ab ', ' abc ', 'abcd' } ;
a_right =right( a ) ; /* right justify */
AA = a//a_right; /* if you print AA, you won't see the blanks */
BB = translate(AA, '*', ' ');
print BB;
When you use the HTML output destination, you can't use the PRINT statement (or PROC PRINT) to determine whether strings have multiple blanks because the HTML renderer "eats" extra blanks.
The last line of your IML program is correct. You can use the RIGHT function (and most other Base SAS functions) in SAS/IML. As you point out, PUT is on the list of exceptions.
The best way to verify that the spaces are really present is to translate them to some character (such as '*') that can be printed and counted. Here is how to use PROC PRINT for your example and how to use the PRINT statement in IML for your second example:
data test;
length a b $ 6 ;
/* 123456 */
a = 'abc ' ;
b = put( a, $6. -R ) ;
put 'a=' a $6. ' b=' b $6. ;
c = right( a ) ;
put 'a=' a $6. ' c=' c $6. ;
run;
/* note that the blanks do not appear when you display them in HTML */
proc print data=test;run;
/* however, you can replace blanks another character to see that they are there */
data test2;
set test;
array X[*] _CHARACTER_;
do i = 1 to dim(X);
X[i] = translate(X[i], '*', ' ');
end;
drop i;
run;
proc iml ;
a={ 'a ', 'ab ', ' abc ', 'abcd' } ;
a_right =right( a ) ; /* right justify */
AA = a//a_right; /* if you print AA, you won't see the blanks */
BB = translate(AA, '*', ' ');
print BB;
Thank you for helping me to understand the HTML renderer and for an excellent example demonstrating proper programming technique.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →