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

Hi! I'm tryin to calculate a mean LS for a lac (see the print screen) Not every cow have the same number of test in their lactation.  How can I code SAS for this: Sum all the LS ne . then divide it by the number of LS ne . And put the result in a new variable called LSmean.

Annie_Fréchette_0-1597083852648.png

Thanks you very much!!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can use the MEAN() function in a data step.

 

Normally, and in the future, we ask you to provide data as SAS data step code and not as screen captures. If you want us to write code to help you, please provide data in the desired form.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You can use the MEAN() function in a data step.

 

Normally, and in the future, we ask you to provide data as SAS data step code and not as screen captures. If you want us to write code to help you, please provide data in the desired form.

--
Paige Miller
Annie_Fréchette
Obsidian | Level 7

Hi! Thank you, will try it! I wasn't sure what part of code I should write because I have just transposed a table...

/*1, tranposer pour avoir une seule ligne par lactation*/
proc sort data=qulac;
by no_ferme cow lac;
run;
proc transpose data=qulac out=qulact prefix=LS_;
var SCC_linear_score;
by no_ferme cow lac;
run;

Should I create a small subsample of data (cards) at first?

 

Thanks, I'm tryin to follow the requests, but strugglin a little bit!;)

PaigeMiller
Diamond | Level 26

Until I see your data as SAS data step code, I can't respond to your specific question.

 

It does seem to me that PROC SORT and PROC TRANSPOSE are not needed, and you didn't even try the MEAN() function in a data step.

--
Paige Miller
Annie_Fréchette
Obsidian | Level 7

hi Paige!

Sorry for everyhting, I accepted your first post cause I did add a mean function and it worked.

/*1, tranposer pour avoir une seule ligne par lactation*/
proc sort data=qulac;
by no_ferme cow lac;
run;
proc transpose data=qulac out=qulact prefix=LS_;
var SCC_linear_score;
by no_ferme cow lac;
run;
/*2 calculer une moyenne par lactation*/
data qulact;
set qulact;
lsmean=mean(ls_1, ls_2, ls_3, ls_4, ls_5, ls_6, ls_7, ls_8, ls_9, ls_10, ls_11, ls_12, ls_13);
run;

So you have answered my question, thanks again. I was writing a part of my "first" code because I tought that is what you have asked, but obviously it is not... I'm not really familiar with the use of macros and my data are sensitive, but in the future i will try my best to meet your demands.

 

Best regards,

Annie

PaigeMiller
Diamond | Level 26

Data on cows is "sensitive"? It's not like you are publishing a person's medical history. And in any event, if it is "sensitive", then you can make up fake data with fake cow ID to match your problem.

--
Paige Miller
Annie_Fréchette
Obsidian | Level 7

Yep! These data are medical histories of these ladies... So it is treated just as humans data.

 I'll make up fake data next time!

 

Thanks again Paige!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 738 views
  • 0 likes
  • 2 in conversation