DATA Step, Macro, Functions and more

Missing data when I run array

Reply
New Contributor
Posts: 3

Missing data when I run array

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?

Super User
Posts: 19,815

Re: Missing data when I run array

Posted in reply to Jackie_1234

Logic error. 

 

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

New Contributor
Posts: 3

Re: Missing data when I run array

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;

New Contributor
Posts: 3

Re: Missing data when I run array

Posted in reply to Jackie_1234

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.

Super User
Super User
Posts: 7,955

Re: Missing data when I run array

Posted in reply to Jackie_1234

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.

Super User
Posts: 5,429

Re: Missing data when I run array

Posted in reply to Jackie_1234
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
Ask a Question
Discussion stats
  • 5 replies
  • 283 views
  • 1 like
  • 4 in conversation