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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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