<?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: FLAGS in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598771#M172709</link>
    <description>&lt;P&gt;If I'm understanding you correctly, you want to filter the data but not do it with your WHERE clause?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You would have to do that within a JOIN; just put AND and then your WHERE filter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;E.g.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AND TRANS_INST_NACRS in ('4452','4248','4107','4131','4044','4268','4063','4144','4200','4845','4171','4138','4618','3982','4734','4071','4073','4238','4097','4124','3987','3972','4137','4168','4264','4123','4685','4245','4870')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are wanting to do a subquery (I don't think SAS allows this?) then you might have to look at doing that with SQL Pass Through (I'm no SAS expert though) but that's likely the route I would take given I come from a SQL background.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Oct 2019 16:33:15 GMT</pubDate>
    <dc:creator>Krueger</dc:creator>
    <dc:date>2019-10-23T16:33:15Z</dc:date>
    <item>
      <title>FLAGS in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598768#M172708</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE FLAGS AS
	SELECT DISTINCT
		A.*,
		CASE WHEN MISSING(D.CIHI_KEY)=0 THEN 'DAD'
		WHEN MISSING(N.CIHI_KEY)=0 THEN 'NACRS'
			ELSE ''
		END AS TRANS_TYPE,
			&lt;FONT color="#FF0000"&gt;CASE WHEN MISSING(sn.CIHI_KEY)=0 THEN 'strokenacrs'
			ELSE ''&lt;/FONT&gt;
		END AS STROKE_NACRS,
			CASE WHEN MISSING(dsc.CIHI_KEY)=0 THEN 'strokenacrsdsc'
			ELSE ''
		END AS Stroke_nacrs_dsc
			FROM FinalDADAbstracts AS A
			LEFT JOIN CIHI.DAD1819Q4 AS D
			ON A.HCNE=D.HCNE AND A.HCNE~='9999999999'
			AND (DATEPART(D.DISCH_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(D.DISCH_DT)+1)
			LEFT JOIN CIHI.NACRS1819Q4 AS N
			ON A.HCNE=n.HCNE AND A.HCNE~='9999999999'
			AND (DATEPART(n.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(n.Reg_DT)+1)
		LEFT JOIN STROKE_NACRS&lt;FONT color="#FF0000"&gt;(where=(STROKE_ISC=1))&lt;/FONT&gt;AS sn
			ON A.HCNE=sn.HCNE AND A.HCNE~='9999999999'
			AND (DATEPART(sn.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(sn.Reg_DT)+1)
		LEFT JOIN Stroke_nacrs_dsc  AS dsc
			ON A.HCNE=dsc.HCNE AND A.HCNE~='9999999999'
		AND A.CIHI_KEY~=dsc.CIHI_KEY 
			AND (DATEPART(dsc.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(dsc.Reg_DT)+1)
		LEFT JOIN INST_EVT AS E
			ON (D.INST_NO=STRIP(PUT(E.INST_AT,BEST32.)) OR n.INST_NO=STRIP(PUT(E.INST_AM,BEST32.)))
			/*where TRANS_INST_NACRS in ('4452','4248','4107','4131','4044','4268','4063','4144','4200','4845','4171','4138','4618','3982','4734','4071','4073','4238','4097','4124','3987','3972','4137','4168','4264','4123','4685','4245','4870')
			or TRANS_INST_DAD IN ('1206','4415','4675','4451','2103','3734','3944','1946','1777','4059','1160','2110','4844','3932','2046','4616','4213','4730','1804','1768','1223','3988','2150','1825','4407','4353','1754','2207','3414','4681','3929','4871')*/
	
	ORDER BY A.CIHI_KEY;
QUIT; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the abve code , I would appreciate if you can advise if there is a way to include some variables from for e.g. the stroke nacrs dataset in the flag instead of using it in the where condition to subset the dataset the way i have done&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a few other flags in the stroke nacrs dataset that i want to include as well so in the end i can get a count for each case if it saisfies all the conditions&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 16:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598768#M172708</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-10-23T16:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: FLAGS in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598771#M172709</link>
      <description>&lt;P&gt;If I'm understanding you correctly, you want to filter the data but not do it with your WHERE clause?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You would have to do that within a JOIN; just put AND and then your WHERE filter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;E.g.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AND TRANS_INST_NACRS in ('4452','4248','4107','4131','4044','4268','4063','4144','4200','4845','4171','4138','4618','3982','4734','4071','4073','4238','4097','4124','3987','3972','4137','4168','4264','4123','4685','4245','4870')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are wanting to do a subquery (I don't think SAS allows this?) then you might have to look at doing that with SQL Pass Through (I'm no SAS expert though) but that's likely the route I would take given I come from a SQL background.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 16:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598771#M172709</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-10-23T16:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: FLAGS in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598772#M172710</link>
      <description>&lt;P&gt;Did you mean records in STROKE_NACRS only or STROKE_NACRS_DSC as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that you may want to add that condition to&lt;/P&gt;
&lt;PRE&gt;LEFT JOIN STROKE_NACRS(where=(STROKE_ISC=1))AS sn
&lt;/PRE&gt;
&lt;P&gt;To subset the data earlier such as&lt;/P&gt;
&lt;PRE&gt;LEFT JOIN STROKE_NACRS(where=(STROKE_ISC=1) and &lt;BR /&gt;        (TRANS_INST_NACRS in ('4452','4248','4107','4131','4044','4268','4063','4144','4200','4845','4171','4138','4618','3982','4734','4071','4073','4238','4097','4124','3987','3972','4137','4168','4264','4123','4685','4245','4870')&lt;BR /&gt;or TRANS_INST_DAD IN ('1206','4415','4675','4451','2103','3734','3944','1946','1777','4059')&lt;BR /&gt;    )AS sn
&lt;/PRE&gt;
&lt;P&gt;Note that TRANS_INST_dat is short because this forum makes it very hard to select some text that extends so far to the right that it is out of the window. But you should get the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 16:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598772#M172710</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-23T16:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: FLAGS in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598773#M172711</link>
      <description>&lt;P&gt;I want to include all the cases from stroke nacrs even if they did not atisfy the requirement for STROKE_ISC=1&amp;nbsp;&lt;/P&gt;&lt;P&gt;but i want to add another&amp;nbsp; flag to my final dataset such that stroke_ISC=1 cases are flagged seperately&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 16:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598773#M172711</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2019-10-23T16:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: FLAGS in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598785#M172716</link>
      <description>So remove any filter that shows the stroke ics (whatever it was im on my phone cant see) then add that column in your select list.&lt;BR /&gt;&lt;BR /&gt;From there you can export the data and use a filter with excel or just requery the new dataset and place your filter on two different datasets.&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Oct 2019 17:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598785#M172716</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-10-23T17:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: FLAGS in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598842#M172744</link>
      <description>&lt;P&gt;Why not this?&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
	CREATE TABLE FLAGS AS
	SELECT DISTINCT
		A.*, &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;sn.STROKE_ISC&lt;/STRONG&gt;&lt;/FONT&gt;
		CASE WHEN MISSING(D.CIHI_KEY)=0 THEN 'DAD'
		WHEN MISSING(N.CIHI_KEY)=0 THEN 'NACRS'
			ELSE ''
		END AS TRANS_TYPE,
			CASE WHEN MISSING(sn.CIHI_KEY)=0 THEN 'strokenacrs'
			ELSE ''
		END AS STROKE_NACRS,
			CASE WHEN MISSING(dsc.CIHI_KEY)=0 THEN 'strokenacrsdsc'
			ELSE ''
		END AS Stroke_nacrs_dsc
			FROM FinalDADAbstracts AS A
			LEFT JOIN CIHI.DAD1819Q4 AS D
			ON A.HCNE=D.HCNE AND A.HCNE~='9999999999'
			AND (DATEPART(D.DISCH_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(D.DISCH_DT)+1)
			LEFT JOIN CIHI.NACRS1819Q4 AS N
			ON A.HCNE=n.HCNE AND A.HCNE~='9999999999'
			AND (DATEPART(n.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(n.Reg_DT)+1)
		LEFT JOIN STROKE_NACRS &lt;FONT color="#FF0000"&gt;/*(where=(STROKE_ISC=1))*/&lt;/FONT&gt; AS sn
			ON A.HCNE=sn.HCNE AND A.HCNE~='9999999999'
			AND (DATEPART(sn.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(sn.Reg_DT)+1)
		LEFT JOIN Stroke_nacrs_dsc  AS dsc
			ON A.HCNE=dsc.HCNE AND A.HCNE~='9999999999'
		AND A.CIHI_KEY~=dsc.CIHI_KEY 
			AND (DATEPART(dsc.Reg_DT)&amp;lt;=DATEPART(A.ADM_DT)&amp;lt;=DATEPART(dsc.Reg_DT)+1)
		LEFT JOIN INST_EVT AS E
			ON (D.INST_NO=STRIP(PUT(E.INST_AT,BEST32.)) OR n.INST_NO=STRIP(PUT(E.INST_AM,BEST32.)))
			/*where TRANS_INST_NACRS in ('4452','4248','4107','4131','4044','4268','4063','4144','4200','4845','4171','4138','4618','3982','4734','4071','4073','4238','4097','4124','3987','3972','4137','4168','4264','4123','4685','4245','4870')
			or TRANS_INST_DAD IN ('1206','4415','4675','4451','2103','3734','3944','1946','1777','4059','1160','2110','4844','3932','2046','4616','4213','4730','1804','1768','1223','3988','2150','1825','4407','4353','1754','2207','3414','4681','3929','4871')*/
	
	ORDER BY A.CIHI_KEY;
QUIT; &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 21:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FLAGS-in-proc-sql/m-p/598842#M172744</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-23T21:25:37Z</dc:date>
    </item>
  </channel>
</rss>

