<?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 Re: Complicated IF/then issues in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410273#M67252</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a list of patient MRNs which fit that category.&amp;nbsp; &amp;nbsp;The next step is to create a variable in my data set where I only have opioid overdoses&amp;nbsp;(the n~2000) and these patients are assigned a "Y".&amp;nbsp; &amp;nbsp;Can i merge this?&amp;nbsp; If so, how?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2017 15:01:11 GMT</pubDate>
    <dc:creator>bsriv</dc:creator>
    <dc:date>2017-11-03T15:01:11Z</dc:date>
    <item>
      <title>Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/409964#M67235</link>
      <description>&lt;P&gt;Hi All:&amp;nbsp; Relatively new to SAS.&amp;nbsp; I'm having difficulties with a dataset, and I apologizes I must explain in generalities because I don't know where to begin.&amp;nbsp; I'll try to include some of the codes, etc I have but I apologize in advance for how vague this may seem... I'm lost!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a large-ish dataset of hospital emergency department (ED) visits (approx 40,000 visits), and I am looking at opioid overdoses and suicide with a number of other predictors.&amp;nbsp; &amp;nbsp;The way the data was delivered to me, the diagnoses I requested are listed as categories with "yes" "no" has level of variables.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Later I am going to create regression models with just the sample of patients with a diagnosis of "Opioid poisoning" (n~2000) with a number of predictors for suicidality as an outcome category (binary outcome "yes" "no").&amp;nbsp; I would like one of those predictors to be previous presentation for a different psychiatric reason (meaning, the patient was previously in the ED NOT for an opioid overdose but FOR a psychiatric diagnosis- again these are categories with "yes" and "no" as levels).&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have number of admissions in total as a separate predictor (I grouped these based on number of times MRN was entered).&amp;nbsp; I also have dates in SAS format DDMONYR 00:00:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to categorizes individual patients (identified by MRN) who have overdosed&amp;nbsp;at least once based on a category AND who have had PREVIOUS presentations for non opioid OD reasons).&amp;nbsp; The n of this total sample should be less than 2000, so not a high number, though I will be drawing from a much larger sample&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips on how/where to begin??&amp;nbsp; &amp;nbsp;If I didn't explain things clearly or if there is any other info I can provide please let me know!!!&amp;nbsp; Unfortunately I cannot post any data because of HIPAA reasons&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 18:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/409964#M67235</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-02T18:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/409975#M67236</link>
      <description>&lt;P&gt;Is each record an admission with a patient identifier and admission characteristics, or is each record a patient with some nonnormalized data structure?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us start someplace. Assume data where each record is an admit with a patient and a diagnosis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data admits;
	input patientid admitdate:mmddyy10. opiod:$1. psych:$1. else:$1.;
datalines;
1 1/1/2017 n y n
1 2/1/2017 n n y
1 3/1/2017 y n n
2 1/1/2017 n n y
2 2/1/2017 n n y
2 3/1/2017 y n n
3 1/1/2017 n y n
3 2/1/2017 n n y
3 3/1/2017 n y n
4 4/1/2017 n y n
4 5/1/2017 n n y
4 6/1/2017 y n n
4 7/1/2017 y n n
4 8/1/2017 y n n
5 6/1/2017 y n n
5 7/1/2017 n n n
5 8/1/2017 n y n
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then let's select anybody who is a y on opiod and also a y on pysch with a date before their y on opiod. In this data 1 and 4.&amp;nbsp; 5 has a psych after and 2 doesn't have a psych.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table opiod_with_psych as
	select distinct a.patientid 
	from admits a inner join admits b on a.patientid = b.patientid
	where a.opiod = 'y' and b.psych = 'y' and b.admitdate &amp;lt; a.admitdate;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That gives us&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="105"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;The SAS System&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;patientid&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start with that and then let's modify.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/409975#M67236</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-11-02T19:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/409978#M67237</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/171600"&gt;@bsriv&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any tips on how/where to begin??&amp;nbsp; &amp;nbsp;If I didn't explain things clearly or if there is any other info I can provide please let me know!!!&amp;nbsp; Unfortunately I cannot post any data because of HIPAA reasons&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will make all your downstream work a lot easier and you'll get much more helpful answers this way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will save you time in the long run.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's instructions on how to convert that data to a SAS data step that you can post on here directly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/409978#M67237</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-02T19:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410273#M67252</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a list of patient MRNs which fit that category.&amp;nbsp; &amp;nbsp;The next step is to create a variable in my data set where I only have opioid overdoses&amp;nbsp;(the n~2000) and these patients are assigned a "Y".&amp;nbsp; &amp;nbsp;Can i merge this?&amp;nbsp; If so, how?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 15:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410273#M67252</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-03T15:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410304#M67260</link>
      <description>&lt;P&gt;I guess more sxplicitly- I have a list of MRNs that fit this critieria.&amp;nbsp; In my larger data set how do I create a variable to which I can assign a "y" or "n" to these MRNs based on whether or not they are on this new table?&amp;nbsp; Thanks!!!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 16:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410304#M67260</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-03T16:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410341#M67264</link>
      <description>&lt;BLOCKQUOTE&gt;I guess more sxplicitly- I have a list of MRNs that fit this critieria.&amp;nbsp; In my larger data set how do I create a variable to which I can assign a "y" or "n" to these MRNs based on whether or not they are on this new table?&amp;nbsp; Thanks!!!&lt;/BLOCKQUOTE&gt;
&lt;P class="1509727308129"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1509727308129"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1509727308129"&gt;I have no idea.&amp;nbsp; We haven't seen even any made-up data.&amp;nbsp; I have no idea what you want to do. You said you already had things in Y/N format.&amp;nbsp;&lt;/P&gt;
&lt;P class="1509727308129"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="1509727308129"&gt;You'll have to provide more information and explanation for further help.&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 16:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410341#M67264</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-11-03T16:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410731#M67297</link>
      <description>&lt;P&gt;Thanks for the suggestions/tips- was out of town, sorry for the delay.&amp;nbsp; &amp;nbsp;Here is fake data simplified from my original set with only the pertinent variables (modified slightly for HIPAA purposes):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.OPIOID11;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input MedRec:BEST12. Enct:BEST12. EnteredDT:DATETIME. opioidx:$1. psychdx:$1.;&lt;BR /&gt;format MedRec BEST12. Enct BEST12. EnteredDT DATETIME.;&lt;BR /&gt;datalines4;&lt;BR /&gt;123456,654387982,04JUN15:16:10:00,2,1&lt;BR /&gt;123456,846397542,08JUL15:17:10:00,1,2&lt;BR /&gt;123456,846397541,09AUG15:18:10:00,1,1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;654321,987654321,09JAN15:13:51:00,1,2&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;654321,123456789,08MAR15:12:30:00,1,1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;654321,867530921,07MAY15:14:20:00,2,1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;987654,&lt;SPAN&gt;987654321,02FEB15:14:40:00,1,2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;987654,123456789, 08MAR15:15:00:00,2,1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;987654,867530921, 04APR15:16:00:00,1,1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MedRec is the patient's medical record number (again, made up).&amp;nbsp; This is assigned to an individual patient and sticks with the patient.&amp;nbsp; Enct is the encounter number, assigned to the patient at an individual visit.&amp;nbsp; opioidx is if the visit is for an opioid overdose (OD).&amp;nbsp; psychdx is for other psychiatric complaint.&amp;nbsp; For both of these, 1=yes, 2=no.&amp;nbsp; For the sake of simplicity each patient will have 3 encounterss.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to identify the patients who have overdosed but&amp;nbsp;PRIOR&amp;nbsp;to any overdose attempt they have had at least one encounterWITHOUT an opioid overdose but WITH a psychiatric diagnosis.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the examples above, I would want to select for patient "123456" because there is an encounter where psychdx=1 (yes for psych dx) AND opioidx=2 (no opioid OD) PRIOR to 2 encounters&amp;nbsp;WITH opioid overdoses (and whether or not a psychdx is present on these encounters doesn't matter)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would NOT want to identify patient "654321" because the&amp;nbsp;opioid ODs preceded the psych diagnosis visits.&amp;nbsp; I WOULD want to identify&amp;nbsp;&lt;SPAN&gt;987654 because an overdose&amp;nbsp;was preceded by at least one psych dx encounter.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have slightly modified the code above:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;BR /&gt;create table opioidpsych as&lt;BR /&gt;select distinct a.MedRec&lt;BR /&gt;from work.opioid11 a inner join work.opioid11 b on a.MedRec = b.MedRec&lt;BR /&gt;where a.opioidx = "1" and b.psychdx="1" and b.EnteredDT &amp;lt; a.EnteredDT;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And as far as I can tell it&amp;nbsp;creates a table for the MedRecs as specified above (meaning the individual patient has at least one opioid OD with a previous visit for psychdx.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once I am done I get a table as follows (c/w above)&lt;/P&gt;&lt;P&gt;data WORK.OPIOIDPSYCH;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input BJH_MedRec:BEST12.;&lt;BR /&gt;format BJH_MedRec BEST12.;&lt;BR /&gt;datalines4;&lt;BR /&gt;123456&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;987654&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So my next question is how to note these IDs (individual patient med rec#s) on my larger data set (work.opioid11), but with the caveat being that each individual line is designated by encounter.&amp;nbsp; For example, I would want to flag patient "123456" twice, the 2nd and third&amp;nbsp;encounters because they were both opioid overdoses with a prior psychiatric diagnosis.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope I am being clear- please let me know if something isn't making sense!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Thanks so much!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&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>Mon, 06 Nov 2017 00:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410731#M67297</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-06T00:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410734#M67299</link>
      <description>&lt;P&gt;What do you want as output from this data set?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 01:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410734#M67299</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-06T01:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410736#M67301</link>
      <description>&lt;P&gt;Hi Reeza:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ultimately I would like to create another variable that notes&amp;nbsp;if an encounter that was an opioid overdose ((opioidx=1) was preceded by a prior encounter for THAT SAME PATIENT (meaning, med recs are the same) where there was not an opioid overdose (opioidx=2) but there was a psychiatric diagnosis given (psychdx=1)&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 01:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410736#M67301</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-06T01:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410741#M67302</link>
      <description>&lt;P&gt;Make it easy for me -post the exact data set as above, but with the output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 02:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410741#M67302</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-06T02:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410748#M67306</link>
      <description>&lt;P&gt;Gotcha:&amp;nbsp; made it even simpler:&lt;/P&gt;&lt;P&gt;data WORK.opioidfake;&lt;BR /&gt;input MedRec:BEST12. Enct:BEST12. EnteredDT DATE. opioidx:$1. psychdx:$1.;&lt;BR /&gt;format MedRec BEST12. Enct BEST12. EnteredDT DATE.;&lt;BR /&gt;datalines;&lt;BR /&gt;123456 654387982 04JUN15 2 1&lt;BR /&gt;123456 846397542 08JUL15 1 2&lt;BR /&gt;123456 846397541 09AUG15 1 1&lt;BR /&gt;654321 987654321 09JAN15 1 2&lt;BR /&gt;654321 123456789 08MAR15 1 1&lt;BR /&gt;654321 867530921 07MAY15 2 1&lt;BR /&gt;987654 987654421 02FEB15 1 2&lt;BR /&gt;987654 123456689 08MAR15 2 1&lt;BR /&gt;987654 867530121 04APR15 1 1&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output (wouldn't allow complete tables but descending labels go across from L to R)&lt;/P&gt;&lt;DIV class="dgrid-header dgrid-header-row ui-widget-header"&gt;&lt;DIV class="dgrid-header dgrid-header-row ui-widget-header"&gt;&amp;nbsp;MedRec&lt;DIV class="dgrid-resize-handle resizeNode-1"&gt;&amp;nbsp;&lt;/DIV&gt;Enct&lt;DIV class="dgrid-resize-handle resizeNode-2"&gt;&amp;nbsp;&lt;/DIV&gt;EnteredDT&lt;DIV class="dgrid-resize-handle resizeNode-3"&gt;&amp;nbsp;&lt;/DIV&gt;opioidx&lt;DIV class="dgrid-resize-handle resizeNode-4"&gt;&amp;nbsp;&lt;/DIV&gt;psychdx&lt;DIV class="dgrid-resize-handle resizeNode-5"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="dgrid-scroller"&gt;&lt;DIV class="dgrid-content ui-widget-content"&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;654387982&lt;/TD&gt;&lt;TD&gt;04JUN15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;846397542&lt;/TD&gt;&lt;TD&gt;08JUL15&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;846397541&lt;/TD&gt;&lt;TD&gt;09AUG15&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;654321&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;TD&gt;09JAN15&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;654321&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;08MAR15&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;654321&lt;/TD&gt;&lt;TD&gt;867530921&lt;/TD&gt;&lt;TD&gt;07MAY15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;987654&lt;/TD&gt;&lt;TD&gt;987654421&lt;/TD&gt;&lt;TD&gt;02FEB15&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;987654&lt;/TD&gt;&lt;TD&gt;123456689&lt;/TD&gt;&lt;TD&gt;08MAR15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-even"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;987654&lt;/TD&gt;&lt;TD&gt;867530121&lt;/TD&gt;&lt;TD&gt;04APR15&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="dgrid-scroller"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dgrid-header dgrid-header-row ui-widget-header"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dgrid-scroller"&gt;&lt;DIV class="dgrid-content ui-widget-content"&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-even"&gt;&lt;P&gt;Then:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table opioidpsych as&lt;BR /&gt;select distinct a.MedRec&lt;BR /&gt;from work.opioidfake a inner join work.opioidfake b on a.MedRec = b.MedRec&lt;BR /&gt;where a.opioidx = "1" and b.psychdx="1" and b.EnteredDT &amp;lt; a.EnteredDT;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignTop"&gt;&lt;DIV class="dijit dijitToolbar"&gt;&lt;DIV class="dgrid-header dgrid-header-row ui-widget-header"&gt;&amp;nbsp;&lt;DIV class="dgrid-sort-arrow ui-icon"&gt;&amp;nbsp;&lt;/DIV&gt;MedRec&lt;DIV class="dgrid-resize-handle resizeNode-1"&gt;&amp;nbsp;&lt;/DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dgrid-scroller"&gt;&lt;DIV class="dgrid-content ui-widget-content"&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;987654&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignCenter dijitContentPaneSingleChild"&gt;&lt;DIV class="dgrid dgrid-grid ui-widget"&gt;&lt;DIV class="dgrid-header dgrid-header-row ui-widget-header"&gt;&lt;DIV class="dgrid-scroller"&gt;&amp;nbsp;&lt;/DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dgrid-scroller"&gt;&lt;DIV class="dgrid-content ui-widget-content"&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd dgrid-selected ui-state-active"&gt;&lt;P&gt;Thanks again!&amp;nbsp; Please let me know if you need more info!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Nov 2017 03:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410748#M67306</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-06T03:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410913#M67327</link>
      <description>&lt;P&gt;I think this gets you pretty close, if not exactly what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input MedRec:BEST12. Enct:BEST12. EnteredDT DATE. opioidx:$1. psychdx:$1.;
format MedRec BEST12. Enct BEST12. EnteredDT DATE.;
datalines;
123456 654387982 04JUN15 2 1
123456 846397542 08JUL15 1 2
123456 846397541 09AUG15 1 1
654321 987654321 09JAN15 1 2
654321 123456789 08MAR15 1 1
654321 867530921 07MAY15 2 1
987654 987654421 02FEB15 1 2
987654 123456689 08MAR15 2 1
987654 867530121 04APR15 1 1
;
run;

proc sort data=have; by medrec entereddt;
run;

data want;
set have;
by medrec;

retain psychflag;

if first.medrec then psychflag=0;
if opioidx='1' and psychflag=1 then output;
if psychdx='1' then psychflag=1;

run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Nov 2017 16:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410913#M67327</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-06T16:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410926#M67328</link>
      <description>&lt;P&gt;Thanks- right now when I do this I am only getting the psychflag=1 lines (about 400 out of my total sample)- how do I get this variable (psychflag) to show in my larger dataset (about 40,000)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 17:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410926#M67328</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-06T17:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410930#M67329</link>
      <description>&lt;P&gt;It matches the output you specified, the two rows. This is why I asked explicitly what you wanted as output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try removing the OUTPUT statement and just creating the flags if that's what you're looking to do.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 17:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410930#M67329</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-06T17:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410936#M67330</link>
      <description>&lt;P&gt;So in the PROC SQL code above, it looks as if that produced the list of med rec numbers that I specifically wanted (these are the patients with an opioid OD with prior psych dx WITHOUT OD.&amp;nbsp; &amp;nbsp;I want my ultimate output to be another variable in my main dataset (n=40,000) that matches these&amp;nbsp;med recs with the appropriate encounters (Opioid ODs that for which the individual MedRec had previously been in the ED for a psych dx).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically, how do I create another variable in my big table (with 40,000) with the Med recs IDd from the proc SQL, assigned to the appropriate Encounters?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if I'm not making sense!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 17:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410936#M67330</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-06T17:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410959#M67331</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Try removing the OUTPUT statement and just creating the flags if that's what you're looking to do.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is still the answer. If you can't get it working, post your modified&amp;nbsp;code and I can help you modify it correctly.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 18:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/410959#M67331</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-06T18:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/411278#M67335</link>
      <description>&lt;P&gt;I'm not getting it.&amp;nbsp; Here is my syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data opioid21;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;set work.opioid20;&lt;BR /&gt;by MedRec;&lt;/P&gt;&lt;P&gt;retain psychflag;&lt;/P&gt;&lt;P&gt;if first.MedRec then psychflag=0;&lt;BR /&gt;psychdx='1' then psychflag=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 17:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/411278#M67335</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-07T17:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/411281#M67336</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; medrec&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token keyword"&gt;retain&lt;/SPAN&gt; psychflag&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;medrec &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; psychflag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; opioidx&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'1'&lt;/SPAN&gt; and psychflag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then flag_record=1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;else flag_record=0;&lt;BR /&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; psychdx&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'1'&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; psychflag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2017 18:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/411281#M67336</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-07T18:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/411287#M67337</link>
      <description>&lt;P&gt;Great thanks!!!!!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 18:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/411287#M67337</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-07T18:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Complicated IF/then issues NEED HELP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/412734#M67427</link>
      <description>&lt;P&gt;I'm not sure what's going on but it doesn't work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt; medrec&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token keyword"&gt;retain&lt;/SPAN&gt; psychflag&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;medrec &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; psychflag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; opioidx&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'1'&lt;/SPAN&gt; and psychflag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; flag_record&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; flag_record&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; psychdx&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'1'&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; psychflag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;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&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 21:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Complicated-IF-then-issues/m-p/412734#M67427</guid>
      <dc:creator>bsriv</dc:creator>
      <dc:date>2017-11-12T21:35:33Z</dc:date>
    </item>
  </channel>
</rss>

