Hi. I want to ask a question regarding an array statement. How do I make the statement for satisfaction question? Honestly, I don't quite understand what the question wants... This is a little bit about the question.. I've also attached the file and the pics.
SATISFACTION.txt data set is an employee’s answer/response on satisfaction question. This question consists of two domains which are Domain A (question 1-6) and Domain B (question 7-15). Each question has four choices of likert scale (1-4).
I have to make a table with error like the pic below. The value should be 1<value=>4. I tried the command below but it didn't work. And for the table without error, the value should be 1<value=<4.
And this is the command that I wrote..
data work.satisfaction;
infile "/home/u62529475/satisfaction.txt" dlm=',';
input EmployeeID 6 Gender $7;
datalines;
run;
proc format;
value $gender 'F'='Female'
'M'='Male';
run;
data work.error;
set satisfaction;
array Response{15} S1-S15;
array Answer{15} 3 _temporary_ (1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3);
do i=1 to 15;
if Answer{i} ge 1 then output work.error;
end;
drop i;
run;
title "Observations in Satisfaction data set with errors";
proc print data=work.error;
format EmployeeID 6. Gender $gender.;
run;
title;
I really don't know how to do this and if anyone can help me asap, I greatly appreciate it.. 🙂
Below your homework done. Please spend the time to understand what I've done as else you won't learn anything but just wasted my time.
data work.satisfaction;
infile "c:\test\satisfaction.txt" dlm=' ' dsd;
input EmployeeID :$10. Gender :$1. (a1-a15) (:best32.);
run;
data without error;
set work.satisfaction;
array _vals{*} a1-a15;
do _i=1 to dim(_vals);
if _vals[_i]<1 or _vals[_i]>4 then
do;
output error;
return;
end;
end;
output without;
drop _i;
run;
proc print data=error;
run;
data without;
set without;
AverageA=mean(of a1-a6);
AverageB=mean(of a7-a15);
Overall_Satisfaction=mean(of a1-a15);
run;
proc print data=without;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.