Hi,
I'm working with longitudinal data and have data on whether participants gambled online for 3 waves.
Here's a screenshot of the data
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.
Like this,
if sixm_w1=0 & sixm_w2=1 then transit12="0-1";
if sixm_w1=1 & sixm_w2=1 then transit12="1-1";
if sixm_w1=1 & sixm_w2=0 then transit12="1-0";
if sixm_w1=0 & sixm_w2=0 then transit12="0-0";
if sixm_w2=0 & sixm_w3=1 then transit23="0-1";
if sixm_w2=1 & sixm_w3=1 then transit23="1-1";
if sixm_w2=1 & sixm_w3=0 then transit23="1-0";
if sixm_w2=0 & sixm_w3=0 then transit23="0-0";
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.
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;
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.
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.
Also you could make your transit variables like this:
transit12 = catx("-",sixm_w1, sixm_w2)
transit23 = catx("-",sixm_w2, sixm_w3)
Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF
View now: on-demand content for SAS users
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.