Help using Base SAS procedures

function mattrib IML

Reply
Occasional Contributor
Posts: 17

function mattrib IML

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
Super User
Posts: 5,254

Re: How to convert a numeric vector into a character one

Define a new vector with char elements, then assign them values from the original vector using the put function.
/Linus
Data never sleeps
Occasional Contributor
Posts: 17

Re: How to convert a numeric vector into a character one

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
Super User
Posts: 5,254

Re: How to convert a numeric vector into a character one

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
Respected Advisor
Posts: 3,777

Re: How to convert a numeric vector into a character one

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]
Occasional Contributor
Posts: 17

Re: How to convert a numeric vector into a character one

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 !
Respected Advisor
Posts: 3,777

Re: How to convert a numeric vector into a character one

> 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.
Occasional Contributor
Posts: 17

Re: How to convert a numeric vector into a character one

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
Ask a Question
Discussion stats
  • 7 replies
  • 161 views
  • 0 likes
  • 3 in conversation