BookmarkSubscribeRSS Feed
nadra
Calcite | Level 5
Hello,

I have a vector of numerics and I need to translate this one into a character vector. For instance a = {1,2,3} I want to have a result b={'1','2','3'}


Thanks

Message was edited by: nadra Message was edited by: nadra
7 REPLIES 7
LinusH
Tourmaline | Level 20
Define a new vector with char elements, then assign them values from the original vector using the put function.
/Linus
Data never sleeps
nadra
Calcite | Level 5
Hello

I defined b as a character vector and I did this : b=put(a,best12.);

but it does not operate ?! Message was edited by: nadra
LinusH
Tourmaline | Level 20
You might need to take a glimpse on the array processing documentation:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002299816.htm
You need to assign values to the individual elements of the vector/array, not the array as a whole.
/Linus
Data never sleeps
data_null__
Jade | Level 19
The syntax you show implies that you are using IML.

[pre]
proc iml;
reset print;
a={1,2,3};
b = char(a,1);
quit;
[/pre]
nadra
Calcite | Level 5
I wanted to have an idea if I can translate the array as a whole to optimize time runing. It appears that I can't do this !! 😞 !

It's clear that if I convert element by element this will take lot of time in my macro !

Data-null , I've tested your program but it shows many errors !
data_null__
Jade | Level 19
> I wanted to have an idea if I can translate the array
> as a whole to optimize time runing. It appears that I
> can't do this !! 😞 !
Are you sure you need to convert the values to character. What is the purpose?

>
> It's clear that if I convert element by element this
> will take lot of time in my macro !

It should not be that slow. Assuming you need to do it at all.

>
> Data-null , I've tested your program but it shows
> many errors !
Worked very well for me. It is a PROC IML program, so I suspect you don't have IML.
nadra
Calcite | Level 5
Hello ,

my purpose was to assign rowname and colname for a matrix using the function mattrib like this :
proc iml;
use panel;
read all var{var1} into sub; sub=unique(sub);n=ncol(sub);
rv=shape(0,n,n);
.
.
.
.
.
mattrib rv r=(sub') c=sub;
CREATE rvtab FROM rv[r=(sub') c=sub];
APPEND FROM rv[r=(sub') c=sub];
CLOSE rvtab ;
run;quit;

sub contains numerics like : 8923, 6322,....

after runing it shows : rowname and colname must be character !!


that why i wanted to convert sub into a character vector! I did this without success!!! Message was edited by: nadra

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1368 views
  • 0 likes
  • 3 in conversation