<?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 How to code a variable (longitudinal data) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-variable-longitudinal-data/m-p/574575#M162384</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with longitudinal data and have data on whether participants gambled online for 3 waves.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a screenshot of the data&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/31117i59592D9EBB41F704/image-size/large?v=1.0&amp;amp;px=-1" border="0" width="600" height="599" title="data.PNG" alt="data.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a transit variable (4 categories) that shows how gambling status changed across wave 1-2 and across wave 2-3 for each participant. So for example, if someone reported not gambling in wave 1 but did in wave 2, I want them coded as "0-1" for the variable transit12.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like this,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sixm_w1=0 &amp;amp; sixm_w2=1 then transit12="0-1";
if sixm_w1=1 &amp;amp; sixm_w2=1 then transit12="1-1";
if sixm_w1=1 &amp;amp; sixm_w2=0 then transit12="1-0";
if sixm_w1=0 &amp;amp; sixm_w2=0 then transit12="0-0";

if sixm_w2=0 &amp;amp; sixm_w3=1 then transit23="0-1";
if sixm_w2=1 &amp;amp; sixm_w3=1 then transit23="1-1";
if sixm_w2=1 &amp;amp; sixm_w3=0 then transit23="1-0";
if sixm_w2=0 &amp;amp; sixm_w3=0 then transit23="0-0";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did so far is use the lag function but I want a way that doesn't use the lag function if possible. And also to create a transit variable for wave 1 to 2 and a transit variable for wave 2 to 3 rather than one variable for all three waves.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA temp;
SET temp;
BY recordno;
lag_online_6m_ofall  = ifn(not(first.recordno),lag(online_6m_ofall),.);
run;

data temp;
set temp;
if lag_online_6m_ofall=. then transit=.;else
if lag_online_6m_ofall=1 and online_6m_ofall=0 then transit= "910"; else
if lag_online_6m_ofall=0 and online_6m_ofall=1 then transit= "901"; else
if lag_online_6m_ofall=1 and online_6m_ofall=1 then transit= "911"; else
if lag_online_6m_ofall=0 and online_6m_ofall=0 then transit= "900";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2019 13:56:32 GMT</pubDate>
    <dc:creator>glg67</dc:creator>
    <dc:date>2019-07-18T13:56:32Z</dc:date>
    <item>
      <title>How to code a variable (longitudinal data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-variable-longitudinal-data/m-p/574575#M162384</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with longitudinal data and have data on whether participants gambled online for 3 waves.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a screenshot of the data&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/31117i59592D9EBB41F704/image-size/large?v=1.0&amp;amp;px=-1" border="0" width="600" height="599" title="data.PNG" alt="data.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a transit variable (4 categories) that shows how gambling status changed across wave 1-2 and across wave 2-3 for each participant. So for example, if someone reported not gambling in wave 1 but did in wave 2, I want them coded as "0-1" for the variable transit12.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like this,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sixm_w1=0 &amp;amp; sixm_w2=1 then transit12="0-1";
if sixm_w1=1 &amp;amp; sixm_w2=1 then transit12="1-1";
if sixm_w1=1 &amp;amp; sixm_w2=0 then transit12="1-0";
if sixm_w1=0 &amp;amp; sixm_w2=0 then transit12="0-0";

if sixm_w2=0 &amp;amp; sixm_w3=1 then transit23="0-1";
if sixm_w2=1 &amp;amp; sixm_w3=1 then transit23="1-1";
if sixm_w2=1 &amp;amp; sixm_w3=0 then transit23="1-0";
if sixm_w2=0 &amp;amp; sixm_w3=0 then transit23="0-0";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did so far is use the lag function but I want a way that doesn't use the lag function if possible. And also to create a transit variable for wave 1 to 2 and a transit variable for wave 2 to 3 rather than one variable for all three waves.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA temp;
SET temp;
BY recordno;
lag_online_6m_ofall  = ifn(not(first.recordno),lag(online_6m_ofall),.);
run;

data temp;
set temp;
if lag_online_6m_ofall=. then transit=.;else
if lag_online_6m_ofall=1 and online_6m_ofall=0 then transit= "910"; else
if lag_online_6m_ofall=0 and online_6m_ofall=1 then transit= "901"; else
if lag_online_6m_ofall=1 and online_6m_ofall=1 then transit= "911"; else
if lag_online_6m_ofall=0 and online_6m_ofall=0 then transit= "900";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 13:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-variable-longitudinal-data/m-p/574575#M162384</guid>
      <dc:creator>glg67</dc:creator>
      <dc:date>2019-07-18T13:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to code a variable (longitudinal data)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-variable-longitudinal-data/m-p/574699#M162446</link>
      <description>&lt;P&gt;Is there any reason that you can't have one record per RecordNo? Is this what you're trying to do before you combine your variables? Not sure about your other columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If yes, then you could use a BY statement in a datastep (with data sorted), and retain values then output at each last.RecordNo to flatten out your table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also you could make your transit variables like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;transit12 = catx("-",sixm_w1, sixm_w2)
transit23 = catx("-",sixm_w2, sixm_w3)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 18:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-code-a-variable-longitudinal-data/m-p/574699#M162446</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-07-18T18:00:58Z</dc:date>
    </item>
  </channel>
</rss>

