DATA Step, Macro, Functions and more

programming help

Reply
New User
Posts: 1

programming help

Could anyone tell me what's wrong with this program?

 

data a.new1;
set a.new;
n1=0;
array k1 {16} k1get k2get k3get k4get k5get k6get k7get k8get k9get k10get k11get k12get k13get k14get k15get k16get;
do i = 1 to 16;
if k1=1 then n1=n1+1;
end;
drop i;
run;

 

Because an error showed up

"Illegal reference to the array k1."

Thank you.

PROC Star
Posts: 1,400

Re: programming help

[ Edited ]
Posted in reply to VirginiaGo

You are not really referencing anything in your array, but your entire array itself. I'm guessing you want to reference the i'th instance of your k1 array, so your line inside your do loop

 

if k1=1 then n1=n1+1;

should be

 

if k1[i]=1 then n1=n1+1;

since right now, you are not using your i variable at all Smiley Happy

 

Super User
Posts: 13,926

Re: programming help

Posted in reply to VirginiaGo

And a good example of possibly rethinking variable names. If you had named the variables Kget1 to Kget16 or GetK1 to GetK16 you could reference them in the array statement as

 

array k1 Kget1-Kget16; or Array k1 GetK1-GetK16;

or if that is all of the "get" variables

array k1 Kget: ;   or array k1 GetK: ;

 

 

Ask a Question
Discussion stats
  • 2 replies
  • 171 views
  • 3 likes
  • 3 in conversation