BookmarkSubscribeRSS Feed
Jackie_1234
Calcite | Level 5

I'm trying to run an array and the code executes with no errors but the output shows missing data.

What am I doing wrong?

5 REPLIES 5
Reeza
Super User

Logic error. 

 

Please post your code and sample input data that demonstrates your issue. 

Jackie_1234
Calcite | Level 5

data sum;
set mysas.test1 end=end nobs=nobs;
array orig(50) item1-item50;
array sums(50) sum1-sum50;
do i = 1 to 50;
sums(i)+orig(i);
end;
if end then do;
do j = 1 to 50;
Item=vname(orig(j));
ItemDifficultyIndex=sums(j)/nobs;
sum=sums(j);
output;
end;
end;
drop i j sum1-sum50;
data sum;
set sum;
if ItemDifficultyIndex ge .70 then Level='+';
if ItemDifficultyIndex lt .30 then Level='-';

title "Item Difficulty (Easiness/Popularity/Prevalence) Indexes";
title3 "Analysis for All Items";
title5 "+ = Easy Item - = Difficult Item";
proc print;
var Item ItemDifficultyIndex Level;
run;
title;
proc means Data=sum n mean std min max maxdec=2 fw=5;
title "Analysis for All Items";
var ItemDifficultyIndex;
run;
data sum;
set sum;
if Level =' ';
title "Item Difficulty (Easiness/Popularity/Prevalence) Indexes";
title3 "Analysis for Retained Items";
proc print;
var Item ItemDifficultyIndex;
run;
title;
proc means Data=sum n mean std min max maxdec=2 fw=5;
title3 "Analysis for Retained Items";
var ItemDifficultyIndex;
run;
title;

Jackie_1234
Calcite | Level 5

My set (mysas.test1) executes successfully when I use proc means, but not with the code above.

I have tried using a different data set and the second data set executes successfully as well.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

This code here immediately looks suspicious - note use the code window - its the {i} or the SAS program icon above your post to put code in as this keeps formatting (i.e. indentations and such like):

data sum;
  set mysas.test1 end=end nobs=nobs;
  array orig(50) item1-item50;
  array sums(50) sum1-sum50;
  do i = 1 to 50;
    sums(i)+orig(i);   <--
  end;

On the row indicated you don't assign anything, maybe you mean sums(i)=<something> + orig(i)?

 

Also, its a good idea to post a small bit of test data, in the form of a datastep, and what you want the output to look like otherwise we are just guessing with no baseline.

LinusH
Tourmaline | Level 20
Which proc means doesn't work?
Try to narrow down the problem by carefully examine the output of each step.
Quite difficult for us to help without input data and desired output.
Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1074 views
  • 1 like
  • 4 in conversation