BookmarkSubscribeRSS Feed
VirginiaGo
Calcite | Level 5

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.

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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 🙂

 

ballardw
Super User

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: ;

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 905 views
  • 3 likes
  • 3 in conversation