<?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 else automation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685520#M207922</link>
    <description>Yes this for Date2 only and we don't want to add date1 every month by own&lt;BR /&gt;</description>
    <pubDate>Mon, 21 Sep 2020 19:20:07 GMT</pubDate>
    <dc:creator>Son_Sam</dc:creator>
    <dc:date>2020-09-21T19:20:07Z</dc:date>
    <item>
      <title>If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685495#M207903</link>
      <description>Hello Everyone,&lt;BR /&gt;I want to automate the sas if else statement at the beginning of each month I have to write if else statement code below:&lt;BR /&gt;Where 2019 is year 01 is month number and Jan is month name in date1&lt;BR /&gt;Data m_000;&lt;BR /&gt;Set m1_000;&lt;BR /&gt;If date1='2019-01-Jan then Date2='2019-1';&lt;BR /&gt;If date1='2019-03-Mar then Date2='2019-03;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;And&lt;BR /&gt;Every time I have to write the code add new month I don't want to add new month every time could this can be automated and how please advice.</description>
      <pubDate>Mon, 21 Sep 2020 18:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685495#M207903</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T18:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685496#M207904</link>
      <description>&lt;P&gt;If your dates are text strings, it is much harder to do. If your dates are valid SAS date values, its much easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But its really not clear to me what you are trying to do, or what input data you have. Do you really have '2019-01-JAN' to indicate January, 2019 where both the '01' and 'JAN' always go together redundantly? Would you ever get '2019-02-JAN' and what would you do with it, what value of Date2 would you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the input data always has dates as text strings in this unusual format, or is that something you have created, which could be simplified?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 18:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685496#M207904</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-21T18:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685500#M207907</link>
      <description>The both the dates are strings&lt;BR /&gt;And we want it in string format&lt;BR /&gt;What if convert them into date format and again in string&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 18:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685500#M207907</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T18:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685501#M207908</link>
      <description>&lt;P&gt;I don't think you have clearly answered most of my questions. Is the '01' and 'Jan' redundant? What happens if you get '02' and 'Jan'?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you simply trying to remove "Jan" and "Mar" from the string?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 18:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685501#M207908</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-21T18:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685505#M207911</link>
      <description>&lt;P&gt;Can you cut and paste in the actual code?&amp;nbsp; The code as is cannot be actual code because it has errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600714451208.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49617iEB4DDDED145E9F6C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600714451208.png" alt="jimbarbour_0-1600714451208.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is very helpful if you post:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Actual code&lt;/LI&gt;
&lt;LI&gt;The log statements if any errors or warnings are issues&lt;/LI&gt;
&lt;LI&gt;The results.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 18:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685505#M207911</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-21T18:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685508#M207913</link>
      <description>&lt;P&gt;If you had SAS dates instead of these silly strings, it would be extremely simple (just a change of format). Storing date values like this is, to be polite, utter stupidity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the first thing you do is fix the process that creates these strings.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 18:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685508#M207913</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-21T18:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685509#M207914</link>
      <description>Data v1;&lt;BR /&gt;Set V2;&lt;BR /&gt;If date1='2019-01-jan' then Date2='2019-01' else&lt;BR /&gt;If date1='2019-02-feb' then Date2='2019-02' else&lt;BR /&gt;If date1='2019-03-mar' then Date2='2019-03'&lt;BR /&gt;Run;&lt;BR /&gt;Where both date1 and Date2 are character.&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685509#M207914</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T19:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685511#M207915</link>
      <description>Can you please provide me the code&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685511#M207915</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T19:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685512#M207916</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/348352"&gt;@Son_Sam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The both the dates are strings&lt;BR /&gt;And we want it in string format&lt;BR /&gt;What if convert them into date format and again in string&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you want to write on clay tablets? Calculate by counting pebbles?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the specific logic behind "we want it in string format"? What specific task is made easier by having the value in a string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS has quite a number of formats for displaying date values in different ways and you can build your own. The first time you need to do almost anything involving the value, such as "beginning of the month" (HINT) then an actual date value makes much more sense.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685512#M207916</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-21T19:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685514#M207917</link>
      <description>&lt;P&gt;If the format of your strings is *very* consistent, then you could just do the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	M1_000;
	INFILE	DATALINES4;
	LENGTH	Date1	$11;
	INPUT	Date1	$;
	DATALINES4;
2019-01-Jan
2019-02-Feb
2019-03-Mar
2019-04-Apr
2019-12-Dec
2020-01-Jan
2020-02-Feb
2020-03-Mar
2020-04-Apr
2020-12-Dec
;;;;
RUN;

DATA	M_000;
	SET	M1_000;
	LENGTH	Date2	$7;
	Date2	=	SUBSTR(STRIP(Date1), 1, 7);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600715213179.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49619iEFD52F7F8108DF22/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600715213179.png" alt="jimbarbour_0-1600715213179.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685514#M207917</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-21T19:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685516#M207918</link>
      <description>It looks like you're just taking the first 7 characters of the string. Why bother with an IF/ELSE at all?&lt;BR /&gt;&lt;BR /&gt;date2 = substr(date1, 1, 7);&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685516#M207918</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-21T19:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685517#M207919</link>
      <description>Yes we can do that and agai. Convert them into the string&lt;BR /&gt;The logic behind is we don't want to add month name string each month&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685517#M207919</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T19:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685518#M207920</link>
      <description>Can we do it for each date1 and how&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685518#M207920</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T19:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685519#M207921</link>
      <description>Did you try it?</description>
      <pubDate>Mon, 21 Sep 2020 19:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685519#M207921</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-21T19:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685520#M207922</link>
      <description>Yes this for Date2 only and we don't want to add date1 every month by own&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685520#M207922</guid>
      <dc:creator>Son_Sam</dc:creator>
      <dc:date>2020-09-21T19:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685521#M207923</link>
      <description>That shouldn't matter with the code I provided. If you seem to think it does, then I clearly don't understand your problem. Please show what the input data looks like, what you want and what you've tried. I'd rather you took the time to fully explain the problem in detail, your responses so far are very brief and do not allow us to understand your problem.</description>
      <pubDate>Mon, 21 Sep 2020 19:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685521#M207923</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-21T19:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685524#M207925</link>
      <description>&lt;P&gt;Can you post your actual data?&amp;nbsp; The contents of M1_000?&amp;nbsp; Is it always very carefully formatted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has a good point that SAS dates are generally the best way to work with dates (instead of plain text).&amp;nbsp; If you convert to SAS dates, you could write:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	M1_000;
	DROP	Temp_String	Temp_Date;
	FORMAT	Date1	YYMMDD10.;
	INFILE	DATALINES4;
	LENGTH	Temp_String	$11;
	INPUT	Temp_String	$;
	Temp_Date	=	CATS(SUBSTR(Temp_String, 1, 7), '-01');
	Date1		=	INPUT(Temp_Date, YYMMDD10.);

	DATALINES4;
2019-01-Jan
2019-02-Feb
2019-03-Mar
2019-04-Apr
2019-12-Dec
2020-01-Jan
2020-02-Feb
2020-03-Mar
2020-04-Apr
2020-12-Dec
;;;;
RUN;

DATA	M_000;
	SET	M1_000;
	LENGTH	Date2	$7;
	Date2	=	PUT(Date1, YYMMD7.);
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600716265930.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49620i31AD61B3127D90CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600716265930.png" alt="jimbarbour_0-1600716265930.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 19:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685524#M207925</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-21T19:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: If else automation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685534#M207929</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/348352"&gt;@Son_Sam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Can you please provide me the code&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Quote from myself:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;So the first thing you do is fix the process that creates these strings."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Show the code that creates these strings.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 20:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-else-automation/m-p/685534#M207929</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-21T20:13:02Z</dc:date>
    </item>
  </channel>
</rss>

