<?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: multiple if condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614984#M179830</link>
    <description>&lt;P&gt;Here's a version that somewhat resembles your DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   do until (last.id);
      set test1;
      by id;
      where term in ("FIRST A" "FIRST B");
      if term="FIRST A" then t1sdt=input(date1,yymmdd10.);
      else if term="FIRST B" then t2sdt=input(date1,yymmdd10.);
   end;
   format t1sdt t2sdt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Jan 2020 15:46:33 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-01-03T15:46:33Z</dc:date>
    <item>
      <title>multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614981#M179827</link>
      <description>&lt;PRE&gt;data test;
   set test1;
   where term in ("FIRST A" "FIRST B");
   if term="FIRST  A" then t1sdt=input(date1,yymmdd10.);
   if term="FIRST B" then t2sdt=input(date1,yymmdd10.);
   format t1sdt t2sdt date9.;
run;&lt;/PRE&gt;
&lt;P&gt;in the above code the output for same id comes in 2 different rows since the conditions are different. Can i make one id like below&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1sdt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t2sdt&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; 10MAR2011&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19MAR2011&lt;/P&gt;
&lt;P&gt;102&amp;nbsp; &amp;nbsp; 12MAR2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20MAR2011&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently it is coming like below&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;t1sdt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t2sdt&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; 10MAR2011&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19MAR2011&lt;/P&gt;
&lt;P&gt;102&amp;nbsp; &amp;nbsp; 12MAR2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;20MAR2011&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614981#M179827</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2020-01-03T15:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614983#M179829</link>
      <description>&lt;P&gt;Since you don't show us (a portion of) the input data, how can we write code (or help you write code) so that the desired results are obtained? We could guess what the input data looks like, but that is often a waste of time ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any event, this may not be the most efficient way to get the result you want, but you could take the output you show and then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=test nway;
    class id;
    var t1sdt t2sdt;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614983#M179829</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-03T15:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614984#M179830</link>
      <description>&lt;P&gt;Here's a version that somewhat resembles your DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   do until (last.id);
      set test1;
      by id;
      where term in ("FIRST A" "FIRST B");
      if term="FIRST A" then t1sdt=input(date1,yymmdd10.);
      else if term="FIRST B" then t2sdt=input(date1,yymmdd10.);
   end;
   format t1sdt t2sdt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614984#M179830</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-03T15:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614987#M179832</link>
      <description>&lt;P&gt;Possibly. But the approach will depend on your actual data.&lt;/P&gt;
&lt;P&gt;For instance, does &lt;STRONG&gt;every single id value have exactly one record with term="FIRST A" and exactly one record with term="FIRST B"?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If the answer is no, and especially if there are more than one of either or both of the FIRST A and FIRST B values, then you will have to show the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should provide some example input data that shows what you start with.&lt;/P&gt;
&lt;P&gt;This does what you show in the case of EXACTLY 2 records matching the Where condition for each ID.&lt;/P&gt;
&lt;PRE&gt;data have;
   input id $ term $ date1 :$10.;
datalines;
101  FIRSTA  20200101
101  FIRSTB  20200102
101  FIRSTC  20200103
102  FIRSTB  20200111
102  FIRSTA  20200112
;

data want;
   set have;
   where term in ("FIRSTA" "FIRSTB");
   by notsorted id;
   retain t1sdt t2sdt;
   if term="FIRSTA" then t1sdt=input(date1,yymmdd10.);
   if term="FIRSTB" then t2sdt=input(date1,yymmdd10.);
   format t1sdt t2sdt date9.;
   if last.id then output;
   drop term date1;
run;
&lt;/PRE&gt;
&lt;P&gt;It will likely do what you want if there is only a single record for each id unless they are not adjacent to each other in the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have more records for the ID that match the WHERE condition then you need 1) to provide actual examples and 2) what the exact output for the example should look like. Which may get fun if you have 7 or 8 matches.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614987#M179832</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-01-03T15:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614990#M179835</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a proc transpose for example to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	input id term $ 5-11 date1 $ 13-20;
	datalines;
101 FIRST A 20110310
101 FIRST B 20110319
102 FIRST A 20190312
102 FIRST B 20110320
;
run;
proc print;

data test2;
   set test1;
   format t1sdt t2sdt date9.;
   where term in ("FIRST A" "FIRST B");
   date = input(date1,yymmdd10.);
   if term="FIRST A" then tsdt = "t1sdt";
   else if term="FIRST B" then tsdt = "t2sdt";
run;

proc transpose data=test out=test3 (drop=_name_);
	var date;
	by id;
	id tsdt;
run;

data want;
	set test3;
	format t1sdt t2sdt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614990#M179835</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-03T15:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614991#M179836</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a proc transpose for example to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
	input id term $ 5-11 date1 $ 13-20;
	datalines;
101 FIRST A 20110310
101 FIRST B 20110319
102 FIRST A 20190312
102 FIRST B 20110320
;
run;
proc print;

data test2;
   set test1;
   format t1sdt t2sdt date9.;
   where term in ("FIRST A" "FIRST B");
   date = input(date1,yymmdd10.);
   if term="FIRST A" then tsdt = "t1sdt";
   else if term="FIRST B" then tsdt = "t2sdt";
run;

proc transpose data=test out=test3 (drop=_name_);
	var date;
	by id;
	id tsdt;
run;

data want;
	set test3;
	format t1sdt t2sdt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614991#M179836</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-03T15:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: multiple if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614995#M179838</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp; I am going with my assumption with some proc sql solution.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp; 's solution is by far the fastest and elegant if your dataset is sorted by ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FWIW&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select id, max((term="FIRST  A")*input(date1,yymmdd10.)) as t1sdt,
max((term="FIRST  B")*input(date1,yymmdd10.)) as t2sdt
from your_dataset
where term in ("FIRST A" "FIRST B")
group by id
order by id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 16:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-if-condition/m-p/614995#M179838</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-03T16:11:02Z</dc:date>
    </item>
  </channel>
</rss>

