<?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: Conditional statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534804#M146804</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261030"&gt;@VRKiwi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would help us to help you if you provide sample data in the form of a working data step (like done below in the code part creating data set have) and then show us the desired/expected result.&lt;/P&gt;
&lt;P&gt;Below code implementing the logic I'm guessing you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm=' ' truncover;
  input Obs src $ filedate :yymmdd8.;
  format filedate yymmdd10.;
  datalines;
1 NW 20070919
2 10Q 20080108
3 NW 20071218
4 10Q 20080404
5 NW 20080318
6 10K 20080711
7 NW 20080709
8 10Q 20080923
9 8K 20080917
10 NW 20080917
11 10Q 20081223
12 NW 20081216
13 10Q 20090323
14 NW 20090317
15 10K 20090716
16 NW 20090714
17 10Q 20090925
18 NW 20090922
19 10Q 20091221
20 NW 20091215
;
run;

proc sort data=have;
  by filedate obs;
run;

data unique_date multi_date;
  set have;
  by filedate;
  if first.filedate and last.filedate then output unique_date;
  else output multi_date;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Feb 2019 12:49:01 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-02-12T12:49:01Z</dc:date>
    <item>
      <title>Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534675#M146750</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find out whether the dates for two separate variables are the same. For example, I want the output to show if the dates for var='X1' and var='X2' are the same (if date of X1 = date of X2). Otherwise, non-matching dates to be in separate output file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using SAS v. 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 01:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534675#M146750</guid>
      <dc:creator>Nkhaledi</dc:creator>
      <dc:date>2019-02-12T01:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534680#M146754</link>
      <description>&lt;P&gt;Question unclear. Supply example data. Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MATCHED UNMATCHED;
  if X1=X2 then output MATCHED; else output UNMATCHED:
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 02:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534680#M146754</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-12T02:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534688#M146756</link>
      <description>&lt;P&gt;The variable (SRC)&amp;nbsp; takes several values, X1, X2, X3, etc. and another variable (fdate) that has different date values per observation. If fdate of X1 equals fdate of X2 then have both in matched file. Otherwise,&amp;nbsp; variables (X1 and X2) with unmatched fdate to be in a separate output file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 02:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534688#M146756</guid>
      <dc:creator>Nkhaledi</dc:creator>
      <dc:date>2019-02-12T02:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534696#M146761</link>
      <description>&lt;P&gt;You make it really hard to help you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We don't even know if you have one or several source tables.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;*Please supply example data.*&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 02:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534696#M146761</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-12T02:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534702#M146762</link>
      <description>Ditto on the fact that it is hard to help the original poster because of no code or no data. Please see the section of this paper on page 5 that discusses How to Ask a Good Question &lt;A href="https://support.sas.com/resources/papers/proceedings12/189-2012.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings12/189-2012.pdf&lt;/A&gt; .&lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Tue, 12 Feb 2019 03:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534702#M146762</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-02-12T03:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534710#M146766</link>
      <description>Sample data:&lt;BR /&gt;Obs src filedate&lt;BR /&gt;&lt;BR /&gt;1 NW 20070919&lt;BR /&gt;2 10Q 20080108&lt;BR /&gt;3 NW 20071218&lt;BR /&gt;4 10Q 20080404&lt;BR /&gt;5 NW 20080318&lt;BR /&gt;6 10K 20080711&lt;BR /&gt;7 NW 20080709&lt;BR /&gt;8 10Q 20080923&lt;BR /&gt;9 8K 20080917&lt;BR /&gt;10 NW 20080917&lt;BR /&gt;11 10Q 20081223&lt;BR /&gt;12 NW 20081216&lt;BR /&gt;13 10Q 20090323&lt;BR /&gt;14 NW 20090317&lt;BR /&gt;15 10K 20090716&lt;BR /&gt;16 NW 20090714&lt;BR /&gt;17 10Q 20090925&lt;BR /&gt;18 NW 20090922&lt;BR /&gt;19 10Q 20091221&lt;BR /&gt;20 NW 20091215&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;If filedate of src='10K' and filedate of src='NW' are the same then output in a matched file. Otherwise, output in unmatched file.</description>
      <pubDate>Tue, 12 Feb 2019 03:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534710#M146766</guid>
      <dc:creator>Nkhaledi</dc:creator>
      <dc:date>2019-02-12T03:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534718#M146773</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;This is partly helpful. However, you do not indicate whether OBS is part of the original data or not. The other thing you don't say is whether your date field is character or numberic. What is the max length of the SRC variable? 3 characters max or 5 characters? &lt;BR /&gt;&lt;BR /&gt;If you are going to create 2 data sets with your conditional logic, then you'll need to use 2 OUTPUT statements in your program. Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data males females;
  set sashelp.class;
  if sex = 'M' then output males;
  else if sex = 'F' then output females;
run;
 
proc print data=males;
  title 'WORK.MALES';
run;
 
proc print data=females;
  title 'WORK.FEMALES';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 04:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534718#M146773</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-02-12T04:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534721#M146775</link>
      <description>&lt;P&gt;There are no 10k.FILEDATE that match SRC.FILEDATE.&lt;/P&gt;&lt;P&gt;What would you do with the 10Q? etc?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 05:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534721#M146775</guid>
      <dc:creator>VRKiwi</dc:creator>
      <dc:date>2019-02-12T05:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534723#M146777</link>
      <description>Thank you Cynthia,&lt;BR /&gt;&lt;BR /&gt;OBS is part of the original data, date field is numeric, SRC is 3 characters.&lt;BR /&gt;&lt;BR /&gt;Your code ignores the date value. For example, if both male &amp;amp; female are born in the same day, then output matched, else output unmatched.</description>
      <pubDate>Tue, 12 Feb 2019 06:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534723#M146777</guid>
      <dc:creator>Nkhaledi</dc:creator>
      <dc:date>2019-02-12T06:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534724#M146778</link>
      <description>And now please provide the expected result of the data you posted.</description>
      <pubDate>Tue, 12 Feb 2019 06:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534724#M146778</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-12T06:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534804#M146804</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261030"&gt;@VRKiwi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would help us to help you if you provide sample data in the form of a working data step (like done below in the code part creating data set have) and then show us the desired/expected result.&lt;/P&gt;
&lt;P&gt;Below code implementing the logic I'm guessing you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm=' ' truncover;
  input Obs src $ filedate :yymmdd8.;
  format filedate yymmdd10.;
  datalines;
1 NW 20070919
2 10Q 20080108
3 NW 20071218
4 10Q 20080404
5 NW 20080318
6 10K 20080711
7 NW 20080709
8 10Q 20080923
9 8K 20080917
10 NW 20080917
11 10Q 20081223
12 NW 20081216
13 10Q 20090323
14 NW 20090317
15 10K 20090716
16 NW 20090714
17 10Q 20090925
18 NW 20090922
19 10Q 20091221
20 NW 20091215
;
run;

proc sort data=have;
  by filedate obs;
run;

data unique_date multi_date;
  set have;
  by filedate;
  if first.filedate and last.filedate then output unique_date;
  else output multi_date;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 12:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/534804#M146804</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-12T12:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/535462#M147042</link>
      <description>&lt;P&gt;Hi Andreas,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; src&amp;nbsp; &amp;nbsp;filedate&lt;/P&gt;&lt;P&gt;1 QTRLY_RPT 2011-01-01&lt;BR /&gt;2 AR 2011-01-01&lt;BR /&gt;3 10Q 2011-01-03&lt;BR /&gt;4 10Q 2011-01-03&lt;BR /&gt;5 10K 2011-01-03&lt;BR /&gt;6 QTRLY_RPT 2011-01-03&lt;BR /&gt;7 10Q 2011-01-03&lt;BR /&gt;8 QTRLY_RPT 2011-01-03&lt;BR /&gt;9 10K 2011-01-03&lt;BR /&gt;10 20F 2011-01-03&lt;BR /&gt;11 10Q 2011-01-03&lt;BR /&gt;12 NW 2011-01-03&lt;BR /&gt;13 10K 2011-01-03&lt;BR /&gt;14 QTRLY_RPT 2011-01-03&lt;BR /&gt;15 NW 2011-01-03&lt;BR /&gt;16 20F 2011-01-03&lt;BR /&gt;17 10K/A 2011-01-03&lt;BR /&gt;18 10K/A 2011-01-03&lt;BR /&gt;19 10K 2011-01-03&lt;BR /&gt;20 10K 2011-01-03&lt;BR /&gt;21 10Q 2011-01-03&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that this is from the whole sample I have (could be different from the one in the earlier post) and you see various SRC types in the output. The code that Patrick provided matched the SRC types that have the same file dates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all,&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 00:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/535462#M147042</guid>
      <dc:creator>Nkhaledi</dc:creator>
      <dc:date>2019-02-14T00:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/535464#M147043</link>
      <description>Hi VRKiwi&lt;BR /&gt;&lt;BR /&gt;If there is no match, then you output the unmatched in a different output file.</description>
      <pubDate>Thu, 14 Feb 2019 00:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/535464#M147043</guid>
      <dc:creator>Nkhaledi</dc:creator>
      <dc:date>2019-02-14T00:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/535475#M147049</link>
      <description>:Hi, you are correct, I used an existing dataset, SASHELP.CLASS which does not have a DATE variable. However, in general the syntax will use the same concepts just different variables and conditions.&lt;BR /&gt;  &lt;BR /&gt;Cynthia</description>
      <pubDate>Thu, 14 Feb 2019 01:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement/m-p/535475#M147049</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-02-14T01:37:10Z</dc:date>
    </item>
  </channel>
</rss>

