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.
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.
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.