BookmarkSubscribeRSS Feed
Ainn_
Calcite | Level 5

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

2 REPLIES 2
Patrick
Opal | Level 21

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;

 

 

Ainn_
Calcite | Level 5
Thank you so much for taking your time to answer this post. I tried to do it on my own but I just cannot find the solution. Anyway, I'll try to understand your command. Thank you once again, I really appreciate it 🙂

SAS Innovate 2025: Register Today!

 

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 811 views
  • 0 likes
  • 2 in conversation