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

I have the following data set resp:

PatientID  RespRate1  RespRate2 ....  RespRate20

XYZ           16                18                       17

ACW          21                17                       21

 

For each row (PatientID) I want to be able to obtain the min, max, mean, and std of the first 10 respiratory rates, then the next ten respiratory rates. I wanted to do this:

 

data resp; set resp;

    min1 = min(of RespRate1-RespRate10);

   max1 = min(of RespRate1-RespRate10);

  mean1 = min(of RespRate1-RespRate10);

  std1 = min(of RespRate1-RespRate10);

   min2 = min(of RespRate11-RespRate12);

   max2 = min(of RespRate11-RespRate20);

  mean2 = min(of RespRate11-RespRate20);

  std2 = min(of RespRate11-RespRate20);

run;

       

Yet the min, max, mean, and std functions don't work unless you list out all of the variables, i.e. min1 = min(RespRate1, RespRate2, RespRate3.... RespRate10).

 

Any ideas on how to do this in Base SAS (I dont want to go over to IML in this instance).

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Try using a double dash (--) not single dash. 

View solution in original post

4 REPLIES 4
Reeza
Super User

Try using a double dash (--) not single dash. 

DocMartin
Quartz | Level 8

This worked! Thanks.

Astounding
PROC Star

There's nothing wrong with the code you are using.  Why do you say it doesn't work?  The only reason I could think of is if you have some character variables instead of numeric.  Of course, you need the numeric values populated ... missing values in the input will generate missing values in the output.

Reeza
Super User

Note double dash only works if the variables are side by side. Other option is to declare arrays which you may want to do, if you're doing multiple calculations. 

 

Note you have a typo in one of your ranges. 

 

Array firstTen(*) resprate1-resprate10;

 

mean1 = mean( of firstTen(*));

mean2 = mean(of resprate1--resprate10);

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1272 views
  • 0 likes
  • 3 in conversation