Hello, I am new to SAS and have a problem using the SAS/IML.
When I use the following code, it shows the following error. The code is from a textbook I use to create a word matrix, but I get an error message and blank matrix.
Can anybody give me some suggestions for this problem?
Thank you.
libname d'/folders/myfolders/song';
options ps=500 ls=132;
data worddata;
infile '/folders/myfolders/song/70songs.txt' delimiter='';
input word: $20. @@;
LW=length(word);
check=substr(word,LW,1);
data voclist;
infile "/folders/myfolders/song/voclist.txt";
input voc $;
proc iml; reset fw=5;
workspace=30000;
use worddata;
read all var {word} into w;
read all var {check} into c;
use voclist;
read all var _char_ into v;
w=concat(w,c);
d=j(nrow(v),nrow(v),0);
LW=length(w);
tagi=0;tagj=0;
check=substr(w,LW,1);
do i=1 to nrow(v);
vis=v(|i,1|);
do j=1 to nrow(v);
vjs=v(|j,1|);
L1=length(vis);
LJ=length(vjs);
k=1; ti=0; tj=0;
jf=j(nrow(w),1,0);
loop: do position = k to (nrow(w)-1) until (check(|position,1|)="#");
wsi=substr(w(|position,1|),1,LI);
wsj=substr(w(|position,1|),1,LJ);
if v(|i,l|)=wsi then do;
tagi=tagi+1; ti=ti+1; end;
if v(|j,1|)=wsj then do;
tagj=tagj+1; tj=tj+1; end;
end;
jf[position,1]=min(ti,tj);
k=position+1; ti=0; tj=0;
if position<nrow(w) then goto loop;
s=sum(jf);
d[i,j]=d(|i,j|)+s;
end;
end;
print d;
create d.network from d;
append from d;
quit;
Error message:
ERROR: (execution) Matrix has not been set to a value
Log:
...
126 end;
ERROR: (execution) Matrix has not been set to a value.
operation : SUBSTR at line 110 column 11
operands : _TEM1001, *LIT1022, LI
_TEM1001 1 row 1 col (character, size 40)
가는 �
*LIT1022 1 row 1 col (numeric)
1
LI 0 row 0 col (type ?, size 0)
statement : ASSIGN at line 110 column 1
127
128 print d;
129
130 create d.network from d;
131 append from d;
132 quit;
I think the problem is a simple typo. The line :
L1=length(vis);
uses the number '1' in the variable name instead of the letter 'I'. Then the error that you have shown occurs at the line,
wsi=substr(w(|position,1|),1,LI);
as the 3rd agrument to the substr() function does not exist.
I think the problem is a simple typo. The line :
L1=length(vis);
uses the number '1' in the variable name instead of the letter 'I'. Then the error that you have shown occurs at the line,
wsi=substr(w(|position,1|),1,LI);
as the 3rd agrument to the substr() function does not exist.
Thank you very much for the quick response.
I changed the code as you commented, and was able to run the code.
-Actually, I had another error with the same typo(1/l) you commented, and also had to fix it.
if v(|i,1|)=wsi then do;
I am still learning to use SAS, so I really appreciate your help.
That must be a VERY old textbook! The indexing syntax v(|j,1|) instead of v[j,1] has not been used in decades.
A good point Rick. I must be showing my age as it didn't appear wrong to me! This type of syntax is from the days when not all computer keyboards had square brackets.
Thank you for the information.
I changed the code, and it worked well.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.