<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic lag function to estimate risk differences in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899866#M40079</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone, I am calculating risk differences with the lag function, I have a variable exposure category (with 3 exposure levels), I want to calculate the difference based on the reference category, but I have not succeeded, any suggestions? help please.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am using this code, there is no problem for the difference between category 2 with the reference, but the calculation of the third category is no longer done with the reference, rather with the previous category (which I understand is what happens with the lag function) is there any way to set a reference category?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data test;&lt;BR /&gt;set test;&lt;BR /&gt;by time exposure;&lt;BR /&gt;rd = risk - lag(risk);&lt;BR /&gt;rr = risk / lag(risk);&lt;BR /&gt;if first.time then rd=.;&lt;BR /&gt;if first.time then rr=.;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2023 02:44:41 GMT</pubDate>
    <dc:creator>Olivi</dc:creator>
    <dc:date>2023-10-25T02:44:41Z</dc:date>
    <item>
      <title>lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899864#M40077</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I am calculating risk differences with the lag function, I have a variable exposure category (with 3 exposure levels), I want to calculate the difference based on the reference category, but I have not succeeded, any suggestions?&lt;BR /&gt;help please&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 02:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899864#M40077</guid>
      <dc:creator>Olivi</dc:creator>
      <dc:date>2023-10-25T02:33:04Z</dc:date>
    </item>
    <item>
      <title>lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899866#M40079</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone, I am calculating risk differences with the lag function, I have a variable exposure category (with 3 exposure levels), I want to calculate the difference based on the reference category, but I have not succeeded, any suggestions? help please.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am using this code, there is no problem for the difference between category 2 with the reference, but the calculation of the third category is no longer done with the reference, rather with the previous category (which I understand is what happens with the lag function) is there any way to set a reference category?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data test;&lt;BR /&gt;set test;&lt;BR /&gt;by time exposure;&lt;BR /&gt;rd = risk - lag(risk);&lt;BR /&gt;rr = risk / lag(risk);&lt;BR /&gt;if first.time then rd=.;&lt;BR /&gt;if first.time then rr=.;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 02:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899866#M40079</guid>
      <dc:creator>Olivi</dc:creator>
      <dc:date>2023-10-25T02:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899877#M40080</link>
      <description>&lt;P&gt;Please amend below HAVE sample data if it is not suitable for your problem.&lt;/P&gt;
&lt;P&gt;Once you've created good enough sample data how should the desired result look like?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd truncover;
  input time exposure risk;
  datalines;
1,1,1
1,1,2
1,2,3
2,1,1
2,3,3
;

data want;
  set have;
  by time exposure;
  rd = risk - lag(risk);
  rr = risk / lag(risk);
  if first.time then call missing(rd,rr);
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2023 06:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899877#M40080</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-25T06:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899878#M40081</link>
      <description>&lt;P&gt;What is the reference category?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please also supply usable example data (in a working data step with datalines), and the expected result.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 06:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/899878#M40081</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-25T06:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900047#M40083</link>
      <description>&lt;P&gt;I will try, thank you&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 01:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900047#M40083</guid>
      <dc:creator>Olivi</dc:creator>
      <dc:date>2023-10-26T01:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900048#M40084</link>
      <description>&lt;P&gt;The exposure category has 3 values (0, 1 and 2) and the reference category is 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input&amp;nbsp;exposure time risk:&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp;0.01413&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0.0125&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0.1077&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0.0491&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;0.0838&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0.0678&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to estimate the risk difference based on the reference category using the lag function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 01:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900048#M40084</guid>
      <dc:creator>Olivi</dc:creator>
      <dc:date>2023-10-26T01:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900052#M40085</link>
      <description>&lt;P&gt;Using your sample data how would the desired result look like? Providing such sample want data often helps a lot to clarify the requirements.&lt;/P&gt;
&lt;P&gt;Not having such want data I'm not sure if I've got below formulas right - but the code should anyway give you the idea.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input exposure time risk;
  datalines;
0 0 0.01413
1 0 0.0125
2 0 0.1077
0 1 0.0491
1 1 0.0838
2 1 0.0678
;

data want;
  set test;
  by time exposure;

  array risks {0:2} 8 _temporary_;

  risks[exposure]=risk;

  if last.time then
    do;
      rd = risks[0] - risks[1];
      rr = risks[0] / risks[2];
      output;
      call missing(of risks[*]);
    end;
  keep time rd rr;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: With a _temporary_ array the values get retained.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 01:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900052#M40085</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-26T01:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: lag function to estimate risk differences</title>
      <link>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900083#M40093</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 06:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/lag-function-to-estimate-risk-differences/m-p/900083#M40093</guid>
      <dc:creator>Olivi</dc:creator>
      <dc:date>2023-10-26T06:39:05Z</dc:date>
    </item>
  </channel>
</rss>

