Hello guys,
I have a data for 11 stress variables. Each item had 4 possible responses (1-4) with “4” indicating the worse stress. I am trying to write a code to print out all subjects who selected "4" for atleast 6 of the 11 items. The part in bold is where i've struggled to do.
Any correction will be appreciated.
data one; set mike;
array stress stress1-stress11;
count=0;
do over stress;
if stress = 4 then count= count+1;
end;
proc print; var stress1-stress11 count;
where count >=6;
run;
Thanks
Here is one way
data have(drop=i j);
array stress{11};
do i=1 to 100;
do j=1 to dim(stress);
stress[j]=rand('integer', 1, 4);
end;
output;
end;
run;
data want(drop=i);
set have;
array stress{11};
count=0;
do i=1 to dim(stress);
if stress[i]=4 then count=count+1;
end;
run;
proc print data=want;
where count ge 6;
run;
Here is one way
data have(drop=i j);
array stress{11};
do i=1 to 100;
do j=1 to dim(stress);
stress[j]=rand('integer', 1, 4);
end;
output;
end;
run;
data want(drop=i);
set have;
array stress{11};
count=0;
do i=1 to dim(stress);
if stress[i]=4 then count=count+1;
end;
run;
proc print data=want;
where count ge 6;
run;
Thank you. That gave me another perspective on how to do the task.
I don't see anything wrong with your code. (Although you should add a RUN statement to end your data step.)
What problems are you actually having? If you are getting errors show the log (make sure to use the INSERT CODE icon on the editor menu to pop-up a window where you can paste the text from the log).
Thank you!
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.