<?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 How to select only a partial set of observations in a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532611#M145955</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;This is a beginner's question.&lt;/P&gt;&lt;P&gt;I am unsure about the correct statement to include in the following program to display only certain values of a few variables.&lt;/P&gt;&lt;P&gt;I need a final output where ''&amp;nbsp;Country eq 'AU' and Job_Title contains 'Sales Rep'; ''&lt;/P&gt;&lt;P&gt;When I use the &lt;STRONG&gt;where&lt;/STRONG&gt;&amp;nbsp; or &lt;STRONG&gt;if&lt;/STRONG&gt; statement in my data step, it's not working. What statement should I use?&lt;/P&gt;&lt;P&gt;Should it be in the data step if perhaps in the proc print step?&lt;/P&gt;&lt;P&gt;All the examples I am trying to find are using the where statement with a set statement while my program uses an infile statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This example contains a dataset csv file.&lt;/P&gt;&lt;P&gt;Please see below the program.&lt;/P&gt;&lt;P&gt;Thank you in advance for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname learn '/home/XXX/learn/';&lt;BR /&gt;&lt;BR /&gt;Filename Emp '/home/XXX/learn/emp.csv'&lt;BR /&gt;&lt;BR /&gt;Data learn.Emp &lt;BR /&gt;&lt;BR /&gt;(keep = EmployeeID FirstName&amp;nbsp;LastName Salary JobTitle HireDate);

infile Emp dsd ;

*if Job_Title contains 'Sales Rep' and Country eq 'AU';

*where Country eq 'AU' and JobTitle contains 'Sales Rep'

informat Hire_Date date9.;

input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate ;

format Salary dollar8. HireDate mmddyy10.;
run;

Title 'Listing of Sales Representatives in Australia';
Proc print data = Emp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Feb 2019 16:32:08 GMT</pubDate>
    <dc:creator>Dublin187</dc:creator>
    <dc:date>2019-02-04T16:32:08Z</dc:date>
    <item>
      <title>How to select only a partial set of observations in a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532611#M145955</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;This is a beginner's question.&lt;/P&gt;&lt;P&gt;I am unsure about the correct statement to include in the following program to display only certain values of a few variables.&lt;/P&gt;&lt;P&gt;I need a final output where ''&amp;nbsp;Country eq 'AU' and Job_Title contains 'Sales Rep'; ''&lt;/P&gt;&lt;P&gt;When I use the &lt;STRONG&gt;where&lt;/STRONG&gt;&amp;nbsp; or &lt;STRONG&gt;if&lt;/STRONG&gt; statement in my data step, it's not working. What statement should I use?&lt;/P&gt;&lt;P&gt;Should it be in the data step if perhaps in the proc print step?&lt;/P&gt;&lt;P&gt;All the examples I am trying to find are using the where statement with a set statement while my program uses an infile statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This example contains a dataset csv file.&lt;/P&gt;&lt;P&gt;Please see below the program.&lt;/P&gt;&lt;P&gt;Thank you in advance for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname learn '/home/XXX/learn/';&lt;BR /&gt;&lt;BR /&gt;Filename Emp '/home/XXX/learn/emp.csv'&lt;BR /&gt;&lt;BR /&gt;Data learn.Emp &lt;BR /&gt;&lt;BR /&gt;(keep = EmployeeID FirstName&amp;nbsp;LastName Salary JobTitle HireDate);

infile Emp dsd ;

*if Job_Title contains 'Sales Rep' and Country eq 'AU';

*where Country eq 'AU' and JobTitle contains 'Sales Rep'

informat Hire_Date date9.;

input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate ;

format Salary dollar8. HireDate mmddyy10.;
run;

Title 'Listing of Sales Representatives in Australia';
Proc print data = Emp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 16:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532611#M145955</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-02-04T16:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only a partial set of observations in a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532616#M145957</link>
      <description>Using the if-statement after input-statement should solve the problem. The input-statement fills the variables.</description>
      <pubDate>Mon, 04 Feb 2019 16:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532616#M145957</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-04T16:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only a partial set of observations in a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532617#M145958</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;it's not working.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What's not working? Can you show us the SASLOG? If you are getting the wrong results, can you explain what is wrong?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, you are missing the DATA command at the beginning of your DATA step and a semi-colon or two.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 16:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532617#M145958</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-04T16:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only a partial set of observations in a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532621#M145959</link>
      <description>&lt;P&gt;The condition should be evaluated AFTER the variables get a value. CONTAINS is only for WHERE and SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname learn '/home/XXX/learn/';

Filename Emp '/home/XXX/learn/emp.csv';
Data learn.Emp (keep = EmployeeID FirstName LastName Salary JobTitle HireDate);
informat Hire_Date date9.;
infile Emp dsd ;
input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate ;

if find(Job_Title, 'Sales Rep', "i") &amp;gt; 0 and Country eq 'AU';

format Salary dollar8. HireDate mmddyy10.;
run;

Title 'Listing of Sales Representatives in Australia';
Proc print data = learn.Emp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 16:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532621#M145959</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-04T16:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to select only a partial set of observations in a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532635#M145963</link>
      <description>&lt;P&gt;Thank you for your help, your solution worked! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;have a lovely day,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 17:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-only-a-partial-set-of-observations-in-a-data-set/m-p/532635#M145963</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-02-04T17:08:35Z</dc:date>
    </item>
  </channel>
</rss>

