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?
Logic error.
Please post your code and sample input data that demonstrates your issue.
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;
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.