BookmarkSubscribeRSS Feed
bsriv
Calcite | Level 5

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;

 

 

Reeza
Super User
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;
bsriv
Calcite | Level 5

Great thanks!!!!!

bsriv
Calcite | Level 5

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 

bsriv
Calcite | Level 5

Nevermind- figured it out!  If I recode the psychdx as excluding opioid OD then this works perfectly.  Thanks!

Reeza
Super User

@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. 

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

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.

 

 

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
  • 20 replies
  • 1435 views
  • 0 likes
  • 3 in conversation