BookmarkSubscribeRSS Feed
PBalte
Calcite | Level 5

Hello all,

 

I am working with a very large (~65,000 observations) repeated measures data set. Currently, the data is setup in long format. How do I create an indicator variable based on change in variable at different timepoints? 

 

This is what I have:

 

ID     Count         Smk_status 

1         1                  Never 

1         2                  Never 

 

2         1                  Former

2         2                  Former

2         3                  Former

 

3         1                  Never 

3         2                  Current

3         3                  Former

 

This is what I want:

 

ID     Count         Smk_status        Smk_trajectory

1         1                  Never                    Never 

1         2                  Never                    Never 

 

2         1                  Former                  Former                   

2         2                  Former                  Former                   

2         3                  Former                  Former                   

 

3         1                  Never                     Inconsistent 

3         2                  Current                  Inconsistent 

3         3                  Former                  Inconsistent 

 

 I can do this in wide format of data but I am just wondering if anyone has any suggestions to do this in long format of data.

 

 

Thanks in advance!

1 REPLY 1
Reeza
Super User

SQL is pretty good at this one.

 

proc sql;
create table want as
select *, case when max(smk_status)=min(smk_status) then min(smk_status)
              else 'Inconsistent' end as smk_trajectory
from have
group by ID,
order by ID, count;
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 569 views
  • 1 like
  • 2 in conversation