<?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 Keeping observations you need in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770372#M30858</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working on a medical database. I will like to keep only selected observations from the dataset. How do i go about it please, expecially when it is a character variable?&lt;/P&gt;
&lt;P&gt;For instance, i want to select only patients with lung cancer from a list of all cancer types. The codes for lung cancer is C340 C341 C342 C343 C348 C349.&lt;/P&gt;
&lt;P&gt;I tried the following but it did not work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TCR.LUNG;&lt;BR /&gt;SET TCR.tx_ltd_use_9518_feb21;&lt;BR /&gt;IF PSITE = 'C340' 'C341' 'C342' 'C343' 'C348' 'C349';&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my log reads:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TCR.LUNG;&lt;BR /&gt;12 SET TCR.tx_ltd_use_9518_feb21;&lt;BR /&gt;13 IF PSITE = 'C340' 'C341' 'C342' 'C343' 'C348' 'C349';&lt;BR /&gt;------&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;14 RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 Sep 2021 03:16:18 GMT</pubDate>
    <dc:creator>Banke</dc:creator>
    <dc:date>2021-09-25T03:16:18Z</dc:date>
    <item>
      <title>Keeping observations you need</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770372#M30858</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working on a medical database. I will like to keep only selected observations from the dataset. How do i go about it please, expecially when it is a character variable?&lt;/P&gt;
&lt;P&gt;For instance, i want to select only patients with lung cancer from a list of all cancer types. The codes for lung cancer is C340 C341 C342 C343 C348 C349.&lt;/P&gt;
&lt;P&gt;I tried the following but it did not work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TCR.LUNG;&lt;BR /&gt;SET TCR.tx_ltd_use_9518_feb21;&lt;BR /&gt;IF PSITE = 'C340' 'C341' 'C342' 'C343' 'C348' 'C349';&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my log reads:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TCR.LUNG;&lt;BR /&gt;12 SET TCR.tx_ltd_use_9518_feb21;&lt;BR /&gt;13 IF PSITE = 'C340' 'C341' 'C342' 'C343' 'C348' 'C349';&lt;BR /&gt;------&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;14 RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 03:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770372#M30858</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-09-25T03:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations you need</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770373#M30859</link>
      <description>&lt;P&gt;To compare against a list of values use the IN operator with a comma separated list of values.&lt;/P&gt;
&lt;PRE&gt;IF PSITE in ('C340', 'C341', 'C342', 'C343', 'C348', 'C349');&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you will have to select by some groups on a regular basis and the groups as such don't change then it might be worth to create a format and use this format for your selections. Below an example how this could work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $mygroups
    'C340', 'C341', 'C342', 'C343', 'C348', 'C349' = 'Lung Cancer'
    other = 'not yet grouped'
  ;
  ;
run;

DATA TCR.LUNG;
  SET TCR.tx_ltd_use_9518_feb21;
  IF put(PSITE,$mygroups.) = 'Lung Cancer';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And last but not least: Given these are diagnostical codes there might already be some table with such grouping defined. If so then you could use this table to dynamically create a format or use a lookup into this table to select the diagnostic code you want.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 03:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770373#M30859</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-25T03:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations you need</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770375#M30860</link>
      <description>&lt;P&gt;Thanks a lot.&lt;/P&gt;
&lt;P&gt;when i used this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;IF PSITE in ('C340', 'C341', 'C342', 'C343', 'C348', 'C349');&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;i got lots of error in my log&lt;/P&gt;
&lt;P&gt;DATA TCR.LUNG;&lt;BR /&gt;20 SET TCR.tx_ltd_use_9518_feb21;&lt;BR /&gt;21 IF PSITE = IN ('C340', 'C341', 'C342', 'C343', 'C348', 'C349');&lt;BR /&gt;22 RUN;&lt;/P&gt;
&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;21:4&lt;BR /&gt;NOTE: &lt;STRONG&gt;Invalid numeric data, PSite='C447' , at line 21 column 4.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;is it because i did not convert to numeric variable?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;for your second suggestion,&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;i was able to create the format but when i tried the second step, i got this:&lt;/P&gt;
&lt;P&gt;DATA TCR.LUNG;&lt;BR /&gt;48 SET TCR.tx_ltd_use_9518_feb21;&lt;BR /&gt;49 IF put(PSITE,$mygroups.) = 'Lung Cancer';&lt;BR /&gt;----------&lt;BR /&gt;48&lt;BR /&gt;ERROR 48-59: The &lt;STRONG&gt;format $MYGROUPS was not found or could not be loaded.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;50 RUN;&lt;/P&gt;
&lt;P&gt;i dont know of any tables with such groupings identified or how to get the tables.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 03:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770375#M30860</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-09-25T03:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations you need</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770379#M30862</link>
      <description>&lt;P&gt;It has worked!&lt;/P&gt;
&lt;P&gt;i added&amp;nbsp; OPTIONS FMTSEARCH = (TCR.FORMATS); before the IF statement so it could locate the format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 04:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770379#M30862</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-09-25T04:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations you need</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770385#M30863</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/394970"&gt;@Banke&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;You need to remove the equal operator and things will work.&lt;BR /&gt;&lt;SPAN&gt;21 IF PSITE &lt;FONT face="arial black,avant garde"&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;=&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt; IN ('C340', 'C341', 'C342', 'C343', 'C348', 'C349');&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Sep 2021 08:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keeping-observations-you-need/m-p/770385#M30863</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-25T08:45:52Z</dc:date>
    </item>
  </channel>
</rss>

