N0o9r5a Tracker
https://communities.sas.com/kntur85557/tracker
N0o9r5a TrackerSun, 03 Nov 2024 23:27:49 GMT2024-11-03T23:27:49ZRe: How to get categorical variables RR estimates in PROC GENMOD
https://communities.sas.com/t5/Statistical-Procedures/How-to-get-categorical-variables-RR-estimates-in-PROC-GENMOD/m-p/761925#M37202
<P>Hello,</P><P>Thank you for the solution! It was a huge help! I haven't learned how to use the macro, so I guess sticking with the proc genmod is more straightforward to me.</P><P>Although I have another weird situation. The code works fine after I did the changes you suggested, but once I add more than 6 or 7 variables in the same model, an error shows "The mean parameter is either invalid or at a limit of its range for some observations" and couldn't show the correct results. At first, I thought because of the limitation of certain categories, but the same error shows even there are more than 2000 samples in that category. Do you happen to know why would this happen?</P><P> </P><P>I appreciate your help! </P>Mon, 16 Aug 2021 21:25:24 GMThttps://communities.sas.com/t5/Statistical-Procedures/How-to-get-categorical-variables-RR-estimates-in-PROC-GENMOD/m-p/761925#M37202N0o9r5a2021-08-16T21:25:24ZHow to get categorical variables RR estimates in PROC GENMOD
https://communities.sas.com/t5/Statistical-Procedures/How-to-get-categorical-variables-RR-estimates-in-PROC-GENMOD/m-p/760775#M37094
<P>Hello everyone, I have a question about how to get categorical variables RR estimates in PROC GENMOD.</P><P> </P><P>My outcome is a binomial variable (death), which 1= event happened, 0=event didn't happen. I listed 3 variables (x, y, z) as exposures that I am looking for to get their RR estimate in the PROC GENMOD procedure. All 3 variables are categorical, x has 5 categories, y has 2 categories, z has 5 categories. There is no missing value among those 4 variables.</P><P> </P><P>I found a PROC GENMOD tutorial from this link: <A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-estimate-relative-risk-in-sas-using-proc-genmod-for-common-outcomes-in-cohort-studies/" target="_blank">https://stats.idre.ucla.edu/sas/faq/how-can-i-estimate-relative-risk-in-sas-using-proc-genmod-for-common-outcomes-in-cohort-studies/ </A></P><P> </P><P>The code I used is:</P><PRE><CODE class=" language-sas">proc genmod data = test;
class x (ref="1")/param=ref;
class y (ref="1")/param=ref;
class z (ref="1")/param=ref;
model death (event="1") = x y z/ dist=binomial link=log;
estimate 'Beta_x' x 1 -1/exp;
estimate 'Beta_y' y 1 -1/exp;
estimate 'Beta_z' z 1 -1/exp;
run;</CODE></PRE><P> </P><P>With the above code, I have this output.</P><P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-08-10 at 5.36.36 PM.png" style="width: 999px;"><img src="https://communities.sas.com/t5/image/serverpage/image-id/62460i5EF46F0A69937D34/image-size/large?v=v2&px=999" role="button" title="Screen Shot 2021-08-10 at 5.36.36 PM.png" alt="Screen Shot 2021-08-10 at 5.36.36 PM.png" /></span></P><P>Although you can see the estimates don't show for different categories of x and z.</P><P> </P><P>I searched for other solutions. Then I found this solution: <A href="https://communities.sas.com/t5/Statistical-Procedures/RR-estimates-using-proc-Genmod-for-categorical-variables/m-p/549129#M27406" target="_blank">https://communities.sas.com/t5/Statistical-Procedures/RR-estimates-using-proc-Genmod-for-categorical-variables/m-p/549129#M27406</A></P><P>link to this website: <A href="https://support.sas.com/kb/23/003.html" target="_blank">https://support.sas.com/kb/23/003.html</A></P><P> </P><P>So I tried to use LSMEANS, the below code is I modified to get categorical variables RR estimates.</P><PRE><CODE class=" language-sas">proc genmod data = test;
class x (ref="1")/param=ref;
class y (ref="1")/param=ref;
class z (ref="1")/param=ref;
model death (event="1") = x y z/ dist=binomial link=log;
<FONT color="#FF0000">lsmeans x z / diff exp cl; /*I only added this line comparing to the code above*/</FONT>
estimate 'Beta_x' x 1 -1/exp;
estimate 'Beta_y' y 1 -1/exp;
estimate 'Beta_z' z 1 -1/exp;
run;</CODE></PRE><P>Although nothing new results showed up with this code, SAS generated the same results as the first screenshot I attached. Also, with the following Note and Warning:</P><P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-08-10 at 5.43.05 PM.png" style="width: 400px;"><img src="https://communities.sas.com/t5/image/serverpage/image-id/62461iB3E272297327EAA2/image-size/medium?v=v2&px=400" role="button" title="Screen Shot 2021-08-10 at 5.43.05 PM.png" alt="Screen Shot 2021-08-10 at 5.43.05 PM.png" /></span></P><P>I am not sure if I used LSMEANS in the right way.</P><P>Also, I wanted to ask what "1 -1" stands for in "estimate 'Beta_x <FONT color="#FF0000">1 - 1</FONT>/ exp"? I have seen some tutorial shows "1 -1" or "1" or "0 1 -1", but I don't really understand the function of it. If there are some tutorials I should know before doing this code, I would love to know about them!</P><P> </P><P>I appreciate your help!</P>Tue, 10 Aug 2021 22:51:38 GMThttps://communities.sas.com/t5/Statistical-Procedures/How-to-get-categorical-variables-RR-estimates-in-PROC-GENMOD/m-p/760775#M37094N0o9r5a2021-08-10T22:51:38ZRe: How to find/flag the second-to-last observation by ID
https://communities.sas.com/t5/SAS-Programming/How-to-find-flag-the-second-to-last-observation-by-ID/m-p/749399#M235483
<P>Hello <a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461">@mkeintz</a> , I just tried your code based on <a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961">@ChrisNZ</a> modified version. It worked perfectly! It also worked for subjects who only had one ob. Thank you for your help! I really appreciate it!</P>Mon, 21 Jun 2021 23:45:53 GMThttps://communities.sas.com/t5/SAS-Programming/How-to-find-flag-the-second-to-last-observation-by-ID/m-p/749399#M235483N0o9r5a2021-06-21T23:45:53ZRe: How to find/flag the second-to-last observation by ID
https://communities.sas.com/t5/SAS-Programming/How-to-find-flag-the-second-to-last-observation-by-ID/m-p/749357#M235456
<P>Hello <a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961">@ChrisNZ</a> , I just tried your code, it works perfectly for subjects who had more than 1 obs, it doesn't work for subjects who only had 1 ob. It's good enough for me! Thank you!</P>Mon, 21 Jun 2021 19:07:51 GMThttps://communities.sas.com/t5/SAS-Programming/How-to-find-flag-the-second-to-last-observation-by-ID/m-p/749357#M235456N0o9r5a2021-06-21T19:07:51ZHow to find/flag the second-to-last observation by ID
https://communities.sas.com/t5/SAS-Programming/How-to-find-flag-the-second-to-last-observation-by-ID/m-p/749175#M235362
<P>Hello everyone, I have a question about how to find/flag the second-to-last observation by the same ID. </P><P> </P><P>The dataset I have like this:</P><TABLE border="1"><TBODY><TR><TD>ID</TD><TD>Assessment date</TD><TD>Status</TD><TD> Status_new1</TD><TD>Status_new2</TD></TR><TR><TD>1</TD><TD>2012-06-19</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>1</TD><TD>2012-06-20</TD><TD>Yes</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>1</TD><TD>2012-06-21</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>2</TD><TD>2012-06-22</TD><TD>.</TD><TD>No</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-23</TD><TD>No</TD><TD>No</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-24</TD><TD>.</TD><TD>No</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-25</TD><TD>No</TD><TD>No</TD><TD>No</TD></TR><TR><TD>3</TD><TD>2012-06-19</TD><TD>Unknown</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-20</TD><TD>Yes</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-21</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-22</TD><TD>.</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-23</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>4</TD><TD>2012-06-01</TD><TD>Unknown</TD><TD>No</TD><TD>Unknown</TD></TR><TR><TD>4</TD><TD>2012-06-03</TD><TD>.</TD><TD>No</TD><TD>Unknown</TD></TR><TR><TD>4</TD><TD>2012-06-05</TD><TD>No</TD><TD>No</TD><TD>Unknown</TD></TR><TR><TD><FONT color="#000000">5</FONT></TD><TD><FONT color="#000000">2012-06-08</FONT></TD><TD><FONT color="#000000">No</FONT></TD><TD><FONT color="#000000">No</FONT></TD><TD><FONT color="#000000">Unknown</FONT></TD></TR></TBODY></TABLE><P> </P><P>The observations that I would like to find/flag is where I used red color:</P><TABLE border="1"><TBODY><TR><TD>ID</TD><TD>Assessment date</TD><TD>Status</TD><TD> Status_new1</TD><TD>Status_new2</TD><TD>count</TD></TR><TR><TD>1</TD><TD>2012-06-19</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD><TD>1</TD></TR><TR><TD><FONT color="#FF0000">1</FONT></TD><TD><FONT color="#FF0000">2012-06-20</FONT></TD><TD><FONT color="#FF0000">Yes</FONT></TD><TD><FONT color="#FF0000">Yes</FONT></TD><TD><FONT color="#FF0000">Yes</FONT></TD><TD><FONT color="#FF0000">2</FONT></TD></TR><TR><TD>1</TD><TD>2012-06-21</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD><TD>3</TD></TR><TR><TD>2</TD><TD>2012-06-22</TD><TD>.</TD><TD>No</TD><TD>No</TD><TD>1</TD></TR><TR><TD>2</TD><TD>2012-06-23</TD><TD>No</TD><TD>No</TD><TD>No</TD><TD>2</TD></TR><TR><TD><FONT color="#FF0000">2</FONT></TD><TD><FONT color="#FF0000">2012-06-24</FONT></TD><TD><FONT color="#FF0000">.</FONT></TD><TD><FONT color="#FF0000">No</FONT></TD><TD><FONT color="#FF0000">No</FONT></TD><TD><FONT color="#FF0000">3</FONT></TD></TR><TR><TD>2</TD><TD>2012-06-25</TD><TD>No</TD><TD>No</TD><TD>No</TD><TD>4</TD></TR><TR><TD>3</TD><TD>2012-06-19</TD><TD>Unknown</TD><TD>Yes</TD><TD>Yes</TD><TD>1</TD></TR><TR><TD>3</TD><TD>2012-06-20</TD><TD>Yes</TD><TD>Yes</TD><TD>Yes</TD><TD>2</TD></TR><TR><TD>3</TD><TD>2012-06-21</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD><TD>3</TD></TR><TR><TD><FONT color="#FF0000">3</FONT></TD><TD><FONT color="#FF0000">2012-06-22</FONT></TD><TD><FONT color="#FF0000">.</FONT></TD><TD><FONT color="#FF0000">Yes</FONT></TD><TD><FONT color="#FF0000">Yes</FONT></TD><TD><FONT color="#FF0000">4</FONT></TD></TR><TR><TD>3</TD><TD>2012-06-23</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD><TD>5</TD></TR><TR><TD>4</TD><TD>2012-06-01</TD><TD>Unknown</TD><TD>No</TD><TD>Unknown</TD><TD>1</TD></TR><TR><TD><FONT color="#FF0000">4</FONT></TD><TD><FONT color="#FF0000">2012-06-03</FONT></TD><TD><FONT color="#FF0000">.</FONT></TD><TD><FONT color="#FF0000">No</FONT></TD><TD><FONT color="#FF0000">Unknown</FONT></TD><TD><FONT color="#FF0000">2</FONT></TD></TR><TR><TD>4</TD><TD>2012-06-05</TD><TD>No</TD><TD>No</TD><TD>Unknown</TD><TD>3</TD></TR><TR><TD><FONT color="#FF0000">5</FONT></TD><TD><FONT color="#FF0000">2012-06-08</FONT></TD><TD><FONT color="#FF0000">No</FONT></TD><TD><FONT color="#FF0000">No</FONT></TD><TD><FONT color="#FF0000">Unknown</FONT></TD><TD><FONT color="#FF0000">1</FONT></TD></TR></TBODY></TABLE><P> </P><P>I am able to create a new variable, named "count" to get a serial number by ID. But I don't know how to find the second to last observation, because the obs are not fixed. Some IDs could only have 1 ob, some IDs could 3 to 10 obs. If there is a way that can create a new variable to flag every second-to-last observation by ID in the same dataset, that would be great!</P><P> </P><P>Thank you for your help!</P>Mon, 21 Jun 2021 03:34:53 GMThttps://communities.sas.com/t5/SAS-Programming/How-to-find-flag-the-second-to-last-observation-by-ID/m-p/749175#M235362N0o9r5a2021-06-21T03:34:53ZRe: Question regarding how to recode a new variable in mutiple obs by the same ID
https://communities.sas.com/t5/SAS-Programming/Question-regarding-how-to-recode-a-new-variable-in-mutiple-obs/m-p/746117#M234024
<P>Hello Tom, thank you so much! I just tried your code, it worked perfectly!! Your way is absolutely easy to understand and follow! Thanks a lot!!</P>Sun, 06 Jun 2021 20:17:31 GMThttps://communities.sas.com/t5/SAS-Programming/Question-regarding-how-to-recode-a-new-variable-in-mutiple-obs/m-p/746117#M234024N0o9r5a2021-06-06T20:17:31ZQuestion regarding how to recode a new variable in mutiple obs by the same ID
https://communities.sas.com/t5/SAS-Programming/Question-regarding-how-to-recode-a-new-variable-in-mutiple-obs/m-p/746104#M234019
<P>Hello everyone, I have a question about how to define status in multiple obs by the same ID. </P><P> </P><P>The dataset I have like this:</P><TABLE border="1"><TBODY><TR><TD>ID</TD><TD>Assessment date</TD><TD>Status</TD></TR><TR><TD>1</TD><TD>2012-06-19</TD><TD>No</TD></TR><TR><TD>1</TD><TD>2012-06-20</TD><TD>Yes</TD></TR><TR><TD>1</TD><TD>2012-06-21</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-22</TD><TD>.</TD></TR><TR><TD>2</TD><TD>2012-06-23</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-24</TD><TD>.</TD></TR><TR><TD>2</TD><TD>2012-06-25</TD><TD>No</TD></TR><TR><TD>3</TD><TD>2012-06-19</TD><TD>Unknown</TD></TR><TR><TD>3</TD><TD>2012-06-20</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-21</TD><TD>No</TD></TR><TR><TD>3</TD><TD>2012-06-22</TD><TD>.</TD></TR><TR><TD>3</TD><TD>2012-06-23</TD><TD>No</TD></TR><TR><TD>4</TD><TD>2012-06-01</TD><TD>Unknown</TD></TR><TR><TD>4</TD><TD>2012-06-03</TD><TD>.</TD></TR><TR><TD>4</TD><TD>2012-06-05</TD><TD>No</TD></TR></TBODY></TABLE><P> </P><P>The dataset I would like to have is like this:</P><TABLE border="1"><TBODY><TR><TD>ID</TD><TD>Assessment date</TD><TD>Status</TD><TD> Status_new1</TD><TD>Status_new2</TD></TR><TR><TD>1</TD><TD>2012-06-19</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>1</TD><TD>2012-06-20</TD><TD>Yes</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>1</TD><TD>2012-06-21</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>2</TD><TD>2012-06-22</TD><TD>.</TD><TD>No</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-23</TD><TD>No</TD><TD>No</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-24</TD><TD>.</TD><TD>No</TD><TD>No</TD></TR><TR><TD>2</TD><TD>2012-06-25</TD><TD>No</TD><TD>No</TD><TD>No</TD></TR><TR><TD>3</TD><TD>2012-06-19</TD><TD>Unknown</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-20</TD><TD>Yes</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-21</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-22</TD><TD>.</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>3</TD><TD>2012-06-23</TD><TD>No</TD><TD>Yes</TD><TD>Yes</TD></TR><TR><TD>4</TD><TD>2012-06-01</TD><TD>Unknown</TD><TD>No</TD><TD>Unknown</TD></TR><TR><TD>4</TD><TD>2012-06-03</TD><TD>.</TD><TD>No</TD><TD>Unknown</TD></TR><TR><TD>4</TD><TD>2012-06-05</TD><TD>No</TD><TD>No</TD><TD>Unknown</TD></TR></TBODY></TABLE><P> </P><P>If any obs in the same ID equal to "Yes", the new status variables (No matter is status_new1 or status_new2) should be equal to "Yes".</P><P>The only difference between status_new1 and status_new2 is demonstrated in ID 4. Considering ID 4's status are not very clear, I want to create status_new2 to do sensitivity analysis to see if there is any difference when I recode them as "No" and "Unknown". </P><P> </P><P>The tricky part to me is how to recode the new variables when the status included two different statuses in the same patient. </P><P> </P><P>I used "where status = "Yes" " to output all the patients who had status equal to "Yes", and created their status_new1 as "Yes". But I don't think I could use the same way to do for status = "No". Because "Yes" and "No" could be mixed. </P><P> </P><P>Thank you for your help!</P>Sun, 06 Jun 2021 19:02:09 GMThttps://communities.sas.com/t5/SAS-Programming/Question-regarding-how-to-recode-a-new-variable-in-mutiple-obs/m-p/746104#M234019N0o9r5a2021-06-06T19:02:09Z