BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yoyong555
Obsidian | Level 7

Hi everyone. 

 

My data looks like the one below.

 

Date         ID     Trial1     Trial2     Trial3

Feb 1        A         74         71

Feb 10      A         71         72

Mar 5        B         76          

Mar 12      C         78          

Mar 23      C         79

Mar 30      C         80         80          80  

 

I need to be able to produce an output like the one below showing the total number of trials per ID and average.

 

ID   NTrials      Mean

A        4               72

B        1               76

C        5               79.4

 

Thank you in advance.

 

Yoyong

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

A relatively straightforward way:

 

data temp;
   set have;
   array trial {3};
   do k=1 to 3;
      if trial{k} > . then do;
         value = trial{k};
         output;
      end;
   end;
run;

proc summary data=temp nway;
   var value;
   class id;
   output out=want (drop=_type_ _freq_) n = NTrials mean = Mean;
run;

View solution in original post

1 REPLY 1
Astounding
PROC Star

A relatively straightforward way:

 

data temp;
   set have;
   array trial {3};
   do k=1 to 3;
      if trial{k} > . then do;
         value = trial{k};
         output;
      end;
   end;
run;

proc summary data=temp nway;
   var value;
   class id;
   output out=want (drop=_type_ _freq_) n = NTrials mean = Mean;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 1575 views
  • 0 likes
  • 2 in conversation