<?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: subsetting data: DATA STEP in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55463#M15445</link>
    <description>Hi:&lt;BR /&gt;
  The syntax of an IF (whether subsetting or with a 'then do") statement is very specific. You cannot string "OR" values/conditions together like this:[pre]&lt;BR /&gt;
if somevar = 111 or 222 or 333 or 444 ....&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Even though some languages might let you do this, SAS will not. Your condition must consist of expressions and logical operators. "or 222" is a valid operator (OR) followed by the constant 222 which is not a valid expression, if what you want to test is whether SOMEVAR=222. Here are some examples:&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF somevar = 111 or somevar = 222 or somevar = 333 ....&lt;BR /&gt;
  &lt;BR /&gt;
IF somevar in (111,222,333,444) ....&lt;BR /&gt;
  &lt;BR /&gt;
IF something in ('value', 'value2', 'value3') ....&lt;BR /&gt;
  &lt;BR /&gt;
IF (something='value' AND another='value2') &lt;BR /&gt;
     OR&lt;BR /&gt;
    (somevar in (111,222)) ....&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
The other approach is to have a lookup table. At some sites, however, you are not allowed to use lookup tables because all the observations being selected must be auditable from within a single program. So, if you do need to use a subsetting IF or an IF with an OUTPUT statement, then your IF statement must follow the rules above.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Fri, 17 Oct 2008 18:38:53 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-10-17T18:38:53Z</dc:date>
    <item>
      <title>subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55461#M15443</link>
      <description>Hi. I'm trying to get about 115 observations from a data set that has 10000. I want all the information for each of the 115 observations.  I tried this the code below and also used an 'or' instead of the 'and'.  But, I can't get a dataset with just the 115 observations. How can I do so?  Thank you.&lt;BR /&gt;
&lt;BR /&gt;
data schaudit;&lt;BR /&gt;
set sch;&lt;BR /&gt;
if schcode =&lt;BR /&gt;
&lt;BR /&gt;
0100610	and&lt;BR /&gt;
0107292	and&lt;BR /&gt;
0109785	and&lt;BR /&gt;
0113514	and&lt;BR /&gt;
0114371	and&lt;BR /&gt;
0115089	and&lt;BR /&gt;
0115105	and&lt;BR /&gt;
0116129	and&lt;BR /&gt;
....i HAVE ALL 115 SCHCODES LISTED...&lt;BR /&gt;
run;

Message was edited by: jcis</description>
      <pubDate>Fri, 17 Oct 2008 17:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55461#M15443</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-17T17:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55462#M15444</link>
      <description>Well, the and does not work at all for your case, but or should, or more convenient in(0100610 ,0107292 , ...). Even more convenient, have your subset data driven by store your subset schcodes in a separate table:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table schaudit as&lt;BR /&gt;
select *&lt;BR /&gt;
from sch&lt;BR /&gt;
where schcode in(select schcode from schcodeTable)&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Is schcode numeric or character? Your code imply numeric, but leading zeroes will be truncated automatically. And what didnt work when using OR? Please show relevant parts from your log. Are you certain that your 115 all exist in your data?&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 17 Oct 2008 17:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55462#M15444</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-10-17T17:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55463#M15445</link>
      <description>Hi:&lt;BR /&gt;
  The syntax of an IF (whether subsetting or with a 'then do") statement is very specific. You cannot string "OR" values/conditions together like this:[pre]&lt;BR /&gt;
if somevar = 111 or 222 or 333 or 444 ....&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Even though some languages might let you do this, SAS will not. Your condition must consist of expressions and logical operators. "or 222" is a valid operator (OR) followed by the constant 222 which is not a valid expression, if what you want to test is whether SOMEVAR=222. Here are some examples:&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF somevar = 111 or somevar = 222 or somevar = 333 ....&lt;BR /&gt;
  &lt;BR /&gt;
IF somevar in (111,222,333,444) ....&lt;BR /&gt;
  &lt;BR /&gt;
IF something in ('value', 'value2', 'value3') ....&lt;BR /&gt;
  &lt;BR /&gt;
IF (something='value' AND another='value2') &lt;BR /&gt;
     OR&lt;BR /&gt;
    (somevar in (111,222)) ....&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
The other approach is to have a lookup table. At some sites, however, you are not allowed to use lookup tables because all the observations being selected must be auditable from within a single program. So, if you do need to use a subsetting IF or an IF with an OUTPUT statement, then your IF statement must follow the rules above.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 17 Oct 2008 18:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55463#M15445</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-10-17T18:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55464#M15446</link>
      <description>Thank you very much!  It worked!</description>
      <pubDate>Fri, 17 Oct 2008 19:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55464#M15446</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-17T19:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55465#M15447</link>
      <description>How do you use the lookup table?   I have created a sas datable with&lt;BR /&gt;
just the codes I want to select for.  Then, I have the table I want to select the observations from based on select codes and update it in the Master datable.&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 24 Oct 2008 17:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55465#M15447</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-24T17:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55466#M15448</link>
      <description>The easiest is to use SQL with a sub-query or an inner join:&lt;BR /&gt;
&lt;BR /&gt;
Proc SQL;&lt;BR /&gt;
create table schaudit as&lt;BR /&gt;
select * &lt;BR /&gt;
from sch&lt;BR /&gt;
where schcode in (select schcodes from sch_lookUpTable)&lt;BR /&gt;
;&lt;BR /&gt;
create table schaudit as&lt;BR /&gt;
select sch.* &lt;BR /&gt;
from sch inner join&lt;BR /&gt;
sch_lookUpTable&lt;BR /&gt;
on sch.schcode eq sch_lookUpTable.schcode&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 24 Oct 2008 19:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55466#M15448</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-10-24T19:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data: DATA STEP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55467#M15449</link>
      <description>Thanks!  I am new to Proc SQL and I love it. Appreciate your help.</description>
      <pubDate>Mon, 27 Oct 2008 18:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/subsetting-data-DATA-STEP/m-p/55467#M15449</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-27T18:58:05Z</dc:date>
    </item>
  </channel>
</rss>

