<?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: Variable subsetting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787495#M251636</link>
    <description>&lt;P&gt;You help us help you if you provide sample data in the form of a data have step as done below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the following giving you the pointers you need? I'd be using option 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input experiment_id type $;
  datalines;
1 A42
1 XX
1 AC
2 XX
2 XX
3 A42
3 AC
;

/* option 1 */
proc sql;
  select
    o.experiment_id,
    o.type
  from
    have o
    inner join
    (select distinct experiment_id from have where type in ('A42','AC') ) s
    on o.experiment_id=s.experiment_id
  ;
quit;

/* option 2 */
proc sql;
  select
    experiment_id,
    type
  from
    have
 where experiment_id in
    (select experiment_id from have where type in ('A42','AC') )
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Dec 2021 01:51:20 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-12-28T01:51:20Z</dc:date>
    <item>
      <title>Variable subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787494#M251635</link>
      <description>&lt;P&gt;Hello everyone.&amp;nbsp; I have included my SAS program below.&amp;nbsp; The code is working at this point, but I need to add a step that will only keep the ExperimentIDs that contain both experiment types (A42 and AC).&amp;nbsp; So if I have 100 observations for ExperimentID '1' but they all contain only type A42, I don't want that ExperimentID in my data.&amp;nbsp; If there are 100 observations for ExperimentID '2' with some being of type A42 and others being type AC, then I would like all of those observations to show.&amp;nbsp; Is this something that can be done in PROC SQL?&amp;nbsp; Any advice/help regarding how I can make this happen?&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
	CREATE TABLE WORK.Experiment_VOLT AS
	SELECT
		t1.ExperimentID,
		t1.STATION,
		t2.TYPE,
		t2.TIMESTAMP,
		t2.VALUE,
		t1.TESTRESULT,
		t2.ADDRESS
	FROM WORK.Experiment t1
		INNER JOIN WORK.DATA_FILTERED t2
			ON (t1.ExperimentID = t2.ExperimentID)
	WHERE TYPE = 'A42' OR TYPE ='AC'
	ORDER BY t1.ExperimentID, t2.TIMESTAMP;  
QUIT;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Dec 2021 01:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787494#M251635</guid>
      <dc:creator>Anthony_eng</dc:creator>
      <dc:date>2021-12-28T01:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Variable subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787495#M251636</link>
      <description>&lt;P&gt;You help us help you if you provide sample data in the form of a data have step as done below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the following giving you the pointers you need? I'd be using option 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input experiment_id type $;
  datalines;
1 A42
1 XX
1 AC
2 XX
2 XX
3 A42
3 AC
;

/* option 1 */
proc sql;
  select
    o.experiment_id,
    o.type
  from
    have o
    inner join
    (select distinct experiment_id from have where type in ('A42','AC') ) s
    on o.experiment_id=s.experiment_id
  ;
quit;

/* option 2 */
proc sql;
  select
    experiment_id,
    type
  from
    have
 where experiment_id in
    (select experiment_id from have where type in ('A42','AC') )
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Dec 2021 01:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787495#M251636</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-12-28T01:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Variable subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787509#M251644</link>
      <description>&lt;P&gt;This will not work in other SQL dialects, but in SAS SQL I think you can get away with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WORK.Experiment_VOLT AS
	SELECT
		t1.ExperimentID,
		t1.STATION,
		t2.TYPE,
		t2.TIMESTAMP,
		t2.VALUE,
		t1.TESTRESULT,
		t2.ADDRESS
	FROM WORK.Experiment t1
		INNER JOIN WORK.DATA_FILTERED t2
			ON (t1.ExperimentID = t2.ExperimentID)
	WHERE TYPE = 'A42' OR TYPE ='AC'
    group by t1.ExperimentID
    having count(distinct t2.TYPE)=2
	ORDER BY t1.ExperimentID, t2.TIMESTAMP;  
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Dec 2021 09:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-subsetting/m-p/787509#M251644</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-12-28T09:28:04Z</dc:date>
    </item>
  </channel>
</rss>

