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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1598 views
  • 0 likes
  • 2 in conversation