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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.