I'm not getting it. Here is my syntax:
data opioid21;
set work.opioid20;
by MedRec;
retain psychflag;
if first.MedRec then psychflag=0;
psychdx='1' then psychflag=1;
run;
data want;
set have;
by medrec;
retain psychflag;
if first.medrec then psychflag=0;
if opioidx='1' and psychflag=1 then flag_record=1;
else flag_record=0;
if psychdx='1' then psychflag=1;
run;
Great thanks!!!!!
I'm not sure what's going on but it doesn't work:
data want;
set have;
by medrec;
retain psychflag;
if first.medrec then psychflag=0;
if opioidx='1' and psychflag=1 then flag_record=1;else flag_record=0;
if psychdx='1' then psychflag=1;
run;
Im not sure what the "psychflag" is supposed to be labeling (I would think the first med rec visit per patient) but it's not, whether I sort it by the date or not. Also, the "flag_records" are not consistent- they all represent overdoses, but not ALL of them for a patient and not always if they were preceded temporally by a psych dx- I'm very lost right now
Nevermind- figured it out! If I recode the psychdx as excluding opioid OD then this works perfectly. Thanks!
@bsriv wrote:
Any tips on how/where to begin?? If I didn't explain things clearly or if there is any other info I can provide please let me know!!! Unfortunately I cannot post any data because of HIPAA reasons
Start by making fake data that replicates you data that you can provide as a data step. It will also work as your simple test case that you can use to test code/processes. There's also public files out there that you could probably use as a starting point to building this. Make sure to include some cases that meet your criteria and some that doesn't so you can make sure it works as expected.
This will make all your downstream work a lot easier and you'll get much more helpful answers this way.
It will save you time in the long run.
Here's instructions on how to convert that data to a SAS data step that you can post on here directly.
Nothing you've stated here is complex but it depends a bit on your data structure. It sounds like you have small data so there's less of a need to have super efficient solutions, simple data steps and SQL steps will work.
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.
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.