<?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: if then count=1 in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667983#M200144</link>
    <description>many thanks, now I see how I should have done it!&lt;BR /&gt;&lt;BR /&gt;thanks &lt;BR /&gt;</description>
    <pubDate>Thu, 09 Jul 2020 08:22:14 GMT</pubDate>
    <dc:creator>MART1</dc:creator>
    <dc:date>2020-07-09T08:22:14Z</dc:date>
    <item>
      <title>if then count=1 in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667477#M199881</link>
      <description>&lt;P&gt;Hello all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to create a calendar showing the working days, but I'm having an issue with one condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I create a "count" column that increases the value only&amp;nbsp;if the day is a&amp;nbsp;working day (and if it's a non working day, it gets the same value of the latest working day.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That works well, but I then would like to assign -1 if the first day of the month is a non working day (and it should then move to 1 once it gets to the first working day).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is&amp;nbsp; as extract of the data and the code I'm using: for 201903 this works fine, but for example for 201906 I'd like to see -1 for the first tow days, then&amp;nbsp; 1,2,3&amp;nbsp;etc for the working days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I don't want to see the 00; instead it should move from -1 to 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data WORK.DATE;
	input DAY MONTH WORKING_DAY $;
	datalines;

20190101 201901 NO
20190102 201901 YES
20190103 201901 YES
20190104 201901 YES
20190105 201901 NO
20190106 201901 NO
20190107 201901 YES
20190108 201901 YES
20190109 201901 YES
20190202 201902 NO
20190203 201902 NO
20190204 201902 YES
20190205 201902 YES
20190206 201902 YES
20190207 201902 YES
20190301 201903 YES
20190302 201903 NO
20190303 201903 NO
20190304 201903 YES
20190305 201903 YES
20190306 201903 YES
20190307 201903 YES
20190601 201906 NO
20190602 201906 NO
20190603 201906 YES
20190604 201906 YES
20190605 201906 YES
20190606 201906 YES
20190607 201906 YES
20190608 201906 NO
20190609 201906 NO
20190610 201906 YES
;
run;

data BDU_TRGR.DATE2;
	set WORK.DATE;
	by MONTH DAY;

	if first.MONTH and WORKING_DAY = "NO" then
		count=-1;

	if first.MONTH and WORKING_DAY = "YES" then
		count=1;
	else if WORKING_DAY = "YES" then
		count+1;
	WD=count;
	drop count;
	format WD z2.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help would e greatly appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 15:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667477#M199881</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-07-07T15:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: if then count=1 in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667494#M199892</link>
      <description>&lt;P&gt;Would this behavior give you what you're looking for?&lt;/P&gt;&lt;P&gt;&lt;EM&gt;(Note: Code edited to correct logic error)&lt;/EM&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.DATE2;
    set WORK.DATE;
    by MONTH DAY;
    
    select;
        when (first.MONTH and WORKING_DAY = "NO")
            count=-1;
        when (first.MONTH and WORKING_DAY = "YES")
            count=1;
        when (count=-1 AND WORKING_DAY = "YES")
            count=1;
        when (WORKING_DAY = "YES")
            count+1;
        otherwise;
    end;
    
    WD=count;
    drop count;
    format WD z2.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Not sure of the other context, but you probably don't need a separate count and WD variable.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 16:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667494#M199892</guid>
      <dc:creator>ketpt42</dc:creator>
      <dc:date>2020-07-07T16:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: if then count=1 in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667495#M199893</link>
      <description>&lt;P&gt;Replace your second step with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DATE1;
	set DATE;
	by MONTH DAY;
    retain WD;
	if first.MONTH then do;
	   if WORKING_DAY = "NO" then  do; WD=-1; output; WD=0; end; else
	   if WORKING_DAY = "YES" then do; WD=1;  output; end;
	end;
	else 
	if working_day= 'NO' then do; wd=-1; output; wd=0; end; else
	if WORKING_DAY = "YES" then do; WD+1; output; end;
	format WD z2.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jul 2020 16:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667495#M199893</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-07T16:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: if then count=1 in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667983#M200144</link>
      <description>many thanks, now I see how I should have done it!&lt;BR /&gt;&lt;BR /&gt;thanks &lt;BR /&gt;</description>
      <pubDate>Thu, 09 Jul 2020 08:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667983#M200144</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-07-09T08:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: if then count=1 in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667984#M200145</link>
      <description>many thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;, that's another clean way to do this&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Jul 2020 08:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-count-1-in-data-step/m-p/667984#M200145</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2020-07-09T08:26:28Z</dc:date>
    </item>
  </channel>
</rss>

