<?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: isolating subjects from a database in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459076#M284556</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175326"&gt;@newsasuser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;It didn't work though, and Im not sure why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could you explain what is happening? Can you show us what you get that is wrong?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there errors in the SASLOG? Please show us the SASLOG.&lt;/P&gt;</description>
    <pubDate>Tue, 01 May 2018 19:42:19 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-05-01T19:42:19Z</dc:date>
    <item>
      <title>isolating subjects from a database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459059#M284554</link>
      <description>&lt;P&gt;I am using a databank to isolate subjects with a diagnosis (dcode) from a specific list. In the dataset, each subject (using the identifier inc_key) may have multiple rows if they have more than one diagnosis. In my code I first created a dummy variable (tbi) for each observation that had a diagnosis of interest. Then I tried to extract only subjects with a "tbi" diagnosis, and not use any subjects that either had no "tbi" or that had tbi+ something else. It didn't work though, and Im not sure why. Help would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;macro for the diagnoses Im interested in:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;length list $30000 ;&lt;BR /&gt;do x=800.0 to 801.9 by 0.01&lt;BR /&gt;,803.0 to 804.9 by 0.01&lt;BR /&gt;,850.0 to 854.1 by 0.01&lt;BR /&gt;,950.1 to 950.3 by 0.01&lt;BR /&gt;,959.01&lt;BR /&gt;,995.55&lt;BR /&gt;;&lt;BR /&gt;list=catx(' ',list,put(x,6.2));&lt;BR /&gt;end;&lt;BR /&gt;call symput('list',list);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;creating dummy variable for tbi:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data mt2.tbi1;set ntdb15.rds_dcode;&lt;BR /&gt;by inc_key;&lt;BR /&gt;tbi=0;&lt;BR /&gt;if dcode in (&amp;amp;list) then tbi=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;output only subjects that have tbi diagnosis and no others:&lt;/STRONG&gt;&lt;BR /&gt;data mt2.tbiplus ;set mt2.tbi1;&lt;/P&gt;&lt;P&gt;by inc_key;&lt;/P&gt;&lt;P&gt;if first.inc_key=last.inc_key;&lt;/P&gt;&lt;P&gt;if tbi=0 then delete;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 19:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459059#M284554</guid>
      <dc:creator>newsasuser</dc:creator>
      <dc:date>2018-05-01T19:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: isolating subjects from a database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459072#M284555</link>
      <description>&lt;P&gt;First, let me suggest that you switch from CALL SYMPUT to CALL SYMPUTX.&amp;nbsp; That will remove thousands of trailing blanks that are part of &amp;amp;LIST.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, you have to picture the BY variables, and which observations are being selected by the final DATA step.&amp;nbsp; The IF statement deletes some, then the DELETE statement deletes more.&amp;nbsp; If a subject has 5 observations, the IF statement deletes the first and last, and only the middle three get inspected by the DELETE statement.&amp;nbsp; That's probably not the correct logic.&amp;nbsp; Here's a way to loop through twice in the same DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;wanted = 'Y';&lt;/P&gt;
&lt;P&gt;do until (last.inc_key);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set ntdb15.rds_dcode;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by inc_key;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if dcode not in (&amp;amp;list) then wanted = 'N';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.inc_key);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set ntdb15.rds_dcode;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by inc_key;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if&amp;nbsp;wanted = 'Y' then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop wanted;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The top DO loop inspects all the observations for a single INC_KEY, and the bottom DO loop runs through the exact same observations (outputting them if appropriate).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 19:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459072#M284555</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-01T19:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: isolating subjects from a database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459076#M284556</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175326"&gt;@newsasuser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;It didn't work though, and Im not sure why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could you explain what is happening? Can you show us what you get that is wrong?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there errors in the SASLOG? Please show us the SASLOG.&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 19:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459076#M284556</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-01T19:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: isolating subjects from a database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459077#M284557</link>
      <description>&lt;P&gt;"Didn't work" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your DCODE variable numeric or character?&lt;/P&gt;
&lt;P&gt;Also you might provide a small example of the critical variables in ntdb15.rds_dcode and then what you expect for the result in mt2.tbiplus.&lt;/P&gt;
&lt;P&gt;I suspect that this might be causing one problem:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; first.inc_key=last.inc_key;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;which only keeps any records with an inc_key with only one record for further processing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;So if that one record does not have the tbi=1 you delete it with the following line.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 19:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459077#M284557</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-01T19:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: isolating subjects from a database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459093#M284558</link>
      <description>&lt;P&gt;There were no errors in the log. When I checked a few of the resulting subjects against the original file where I got all the diagnoses, I saw that some of those subjects actually had additional diagnoses that I wasnt interested in. That's what I mean by not working&lt;/P&gt;</description>
      <pubDate>Tue, 01 May 2018 20:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/isolating-subjects-from-a-database/m-p/459093#M284558</guid>
      <dc:creator>newsasuser</dc:creator>
      <dc:date>2018-05-01T20:17:25Z</dc:date>
    </item>
  </channel>
</rss>

