BookmarkSubscribeRSS Feed
mgrzyb
Quartz | Level 8

Hello. I hope you are all fine!  

 

I need help.  I want calculated mean differences for many physiological variables for longitudinal analyses.  For example, my data looks like this:

 

 

data have;  /*Have_hrdiff = Mean Heart Rate difference bt

each treatment_number */

 

input id  treatment_number  ave_hrdiff ;

datalines;

cards;

 

1     1     -4

1     2     6

1     3     7

1     4     -8

1     5     -2

1     6     -4

2     1     -2

2     2     3

2     3     8

2     4     7

4     1     -9

4     2     2

4     3     8

4     4     9

.

.

.

.

1626  1     -3

1626  2     -3

1626  3     -8

1626  4     5

;

run;

 

 

Data want;

 Set have;

 

Output Desired:

I would like to have the changes in HR (heartrate) labeled as:

 

  11hr 12hr 13hr   14hr  15hr 16hr

 

/*11hr means 1st patient’s 1st heart rate difference,

  12hr means 1st patient’s 2nd heart rate difference, etc.

  21 means 2nds patient’s 1st heart rate difference, etc.*/

 

 21hr 22hr 23hr   24hr

 41hr 42hr 43hr   44hr

 16261hr 16262hr 161263hr 161264hr

 

 

 

How would I code this the differences in an efficient manner? 

 

Thank you, Kindly!!!!

 

10 REPLIES 10
ballardw
Super User

Best is to present an example of desired result given an example input data set with both as data step code.

 

You say you want

I would like to have the changes in HR (heartrate) labeled as:

  11hr 12hr 13hr   14hr  15hr 16hr

I really don't see what you intend for an output. Do you want to add a variable with values like 11hr?

 

mgrzyb
Quartz | Level 8

Thank you for responding. 

 

 

If I knew the code, I wouldn't be asking. I just want the variables to be labeled so I can use something like s1-s20.  

 

 

Thanks. 

Reeza
Super User

He's asking for your data as a data step, not the solution code. 

Instructions on how to do that are here:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Your question is unclear, so some clarification on exactly what your input looks like and what your desired output would be helpful. 

 


@mgrzyb wrote:

Thank you for responding. 

 

 

If I knew the code, I wouldn't be asking. I just want the variables to be labeled so I can use something like s1-s20.  

 

 

Thanks. 


 

 

ballardw
Super User

This adds a variable with a label to the data row:

data have;
input id  treatment_number  ave_hrdiff ;
length hrlabel $ 8;
hrlabel = catt('hr',id,treatment_number);
datalines;
1     1     -4
1     2     6
1     3     7
1     4     -8
1     5     -2
1     6     -4
2     1     -2
2     2     3
2     3     8
2     4     7
4     1     -9
4     2     2
4     3     8
4     4     9
1626  1     -3
1626  2     -3
1626  3     -8
1626  4     5
;
run;

but I don't see how that gets any closer "calculated mean differences for many physiological variables for longitudinal analysis".

 

 

Be advised that when you say "LABEL" in terms of SAS coding you are possibly not meaning what a SAS LABEL is. Label is text that appears referencing the variable in place of the variable name for prettier output:

proc print data=have noobs label;
  label id='Patient ID'
        ave_hrdiff='Average Heart Rate Difference'
  ;
run;

The key here is LABEL is a variable property that does not change with the values of any variable.

 

 

Please examine the output here:

Proc summary data=have;
   class id treatment_number;
   var ave_hrdiff;
   output out=havesum mean=;
run;
proc print;
run;

The first row, where _type_=0 is the overall mean of the analysis variable(s) appearing on the VAR statement.

 

_type_=1 summarizes by treatment ignoring id. _type_=2 summarizes by ID ignoring treatment, _type_= 3 basically copies the input data as you do not have any duplicates of ID*treatment combinations, but that is what the mean represents.

PGStats
Opal | Level 21

Do you want

 

one observation per patient, with all the hr diffs on the same row

 

or

 

a single observation with all the patients and all the hr diffs?

PG
katemcguckin
Fluorite | Level 6

Hi - thanks for your note.

 

 

I am trying to get them in order so they will go across with all the HRdifferences in 1 row in some type of numerical order so I don't  have to transpose the data myself and rename every HR difference per patient. 

 

Thanks. 

katemcguckin
Fluorite | Level 6

I already have the mean value for each value regardless of how many visits they have had. 

 

I need to make a graph of those on one med vs another, so I would like something simple like 

 

for patient 1 = 11hr-134hr = 1st heart rate at time 1 and  1st heart rate at time 34, so I don't have to rename them myself. 

 

I is for the patient.  The 2nd and 3rd number represents the visit for the HR measurement.  Thanks. 

 

I am getting hopeless.  There are many people who just refer me to a paper, but I am new to this.  

 

Have a good one. 

 

 

 

 

ballardw
Super User

Here is a hint:

Take a small example of your data, maybe two ids as shown above with 4 or 5 values per ID.

 

Then take us through how you expect to calculate your "longitudinal mean difference" using that data. Describe step by step what is summed and then how the "mean" should be taken and what the final result of the calculation should look like.

 

I have a very strong suspicion that you are trying to force SAS to work like a spreadsheet, which is usually a poor approach to the problem as SAS works quite differently.

 

mgrzyb
Quartz | Level 8

Hi  and thanks. 

 

I have never used a spreadsheet. So I just want to graph one group of patients on drug A with all their repeated times, and I figured it may be easier like having time1-timeX for 1 patient, and time 1 and time X for those on Drug B. 

 

I already got the mean differences.  For another analyses,  I had 2 groups, and their scores were s1-s20 per group. dID  and Manova nd got good results.  

 

I just don't want have to retype each person's Heart rate as hr1-hrx for one patient, and hr2-hrx for the others and so on.

 

If you have any ideas, I would appreciate them.  Marysia

ballardw
Super User

@mgrzyb wrote:

Hi  and thanks. 

 

I have never used a spreadsheet. So I just want to graph one group of patients on drug A with all their repeated times, and I figured it may be easier like having time1-timeX for 1 patient, and time 1 and time X for those on Drug B. 

 

I already got the mean differences.  For another analyses,  I had 2 groups, and their scores were s1-s20 per group. dID  and Manova nd got good results.  

 

I just don't want have to retype each person's Heart rate as hr1-hrx for one patient, and hr2-hrx for the others and so on.

 

If you have any ideas, I would appreciate them.  Marysia


You did not include any drug information so at this point not much I can do with that but to create a plot of each patient:

data have;  
input id  treatment_number  ave_hrdiff ;
datalines;
1     1     -4
1     2     6
1     3     7
1     4     -8
1     5     -2
1     6     -4
2     1     -2
2     2     3
2     3     8
2     4     7
4     1     -9
4     2     2
4     3     8
4     4     9
;
run;
/* just in case*/
proc sort data=have;
by id treatment_number;
run;

proc sgplot data=have;
   by id;
   scatter x=treatment_number y=ave_hrdiff;
run;

If your data set has an actual variable for the drug you could make the plot code:

 

proc sgplot data=have;
   by id;
   scatter x=treatment_number y=ave_hrdiff / group=drug;
run;

Which would show each series of values for ave_hrdiff a differenct color and/or symbol (depending on ODS style in effect) for each drug. A legend would appear below the graph with a key.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 10 replies
  • 1076 views
  • 0 likes
  • 5 in conversation