<?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: How to execute a different group of statements depending on which variable contains invalid valu in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328640#M271703</link>
    <description>&lt;P&gt;I think you have to reset _ERROR_=0&amp;nbsp;within&amp;nbsp;each do group.&amp;nbsp;&amp;nbsp; Otherwise all do groups subsequent to the first variable provoking an error will be executed.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2017 05:04:02 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-01-31T05:04:02Z</dc:date>
    <item>
      <title>How to execute a different group of statements depending on which variable contains invalid value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328461#M271696</link>
      <description>&lt;P&gt;If a data error occours, SAS will&lt;/P&gt;&lt;P&gt;- write &amp;nbsp;in the log&amp;nbsp;an invalid data note, information about the variable for which there&amp;nbsp;is the invalid value and the observation &lt;SPAN&gt;containing the invalid value&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;- set the variable _ERROR_ to 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to execute a different group of statements depending on which variable contains the invalid value, for example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if the invalid value is for var1 then
   do;
      ...;
   end;
else if the invalid value is for var2 then
   do;
      ...;
   end;
else 
   do;
      ...;
   end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I do it?&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 15:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328461#M271696</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-01-30T15:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328464#M271697</link>
      <description>&lt;P&gt;A good start:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post the code that might generate a message about invalid data.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 15:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328464#M271697</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-30T15:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328468#M271698</link>
      <description>&lt;P&gt;Test data - in the form of a datastep, and required output. &amp;nbsp;It depends on what you are checking, personally I would avoid checking the SAS output and pre-validate yourself. &amp;nbsp;Also note, it may be tidier to have a select() statement - but again depends on your data/logic.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 15:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328468#M271698</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-30T15:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328493#M271699</link>
      <description>&lt;P&gt;What do you mean by invalid value ?&lt;/P&gt;
&lt;P&gt;Is it a numeric or a character type variable?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you expecting a numeric value in a char type variable ?&lt;/P&gt;
&lt;P&gt;Do you have a table or informat to check validity of the variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need give more information about your variables, expected values and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to define invalid values.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 16:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328493#M271699</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-30T16:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328512#M271700</link>
      <description>&lt;P&gt;Are you looking for this only for a program that reads external data? If so I suspect that you will need to modify your input statement into something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input var1 @;&lt;/P&gt;
&lt;P&gt;if _error_ then do;&lt;/P&gt;
&lt;P&gt;&amp;lt;code&amp;gt;;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;input var2 @;&lt;/P&gt;
&lt;P&gt;if _error_ then do;&lt;/P&gt;
&lt;P&gt;&amp;lt;code&amp;gt;;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;As when the _error_ flag is thrown it applies to a statement. If you have multiple variables with issues then you don't know which one.&lt;/P&gt;
&lt;P&gt;HOWEVER if the data is 100% always and forever supposed to have some value assigned you could use :&lt;/P&gt;
&lt;P&gt;If missing(var1) then do;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;After the current input statement.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 17:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328512#M271700</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-30T17:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328515#M271701</link>
      <description>&lt;P&gt;You are right... please find below the code generating error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;
 infile datalines;
 informat timestamp_1 E8601DZ26.;
 format timestamp_1 DATETIME.;
 informat timestamp_2 E8601DZ26.;
 format timestamp_2 DATETIME.;

 input 
   timestamp_1
   timestamp_2;

 datalines;
 2013-07-29T11:55:21Z 2016-07-29T11:35:21Z 
 2014-08-04T22:12:49+02:00 2011-11-15
 2018-11-1 2016-07-29T11:35:21Z
 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It follows that the dates are not imported.&lt;/P&gt;&lt;P&gt;I have already tried to import everything by informat ANYDTDTM. but timestamps are not always correctly imported.&lt;/P&gt;&lt;P&gt;I would like to be able to import both the timestamps and dates correctly.&amp;nbsp;I thought to set some condition&amp;nbsp;to import&amp;nbsp;&lt;SPAN&gt;by informat E8601DZ26.&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;by default, and&amp;nbsp;switch to&amp;nbsp;ANYDTDTM. when the field of the variable contains a date.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any other suggestion is welcome.&lt;/SPAN&gt;&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>Mon, 30 Jan 2017 17:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328515#M271701</guid>
      <dc:creator>user_</dc:creator>
      <dc:date>2017-01-30T17:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328534#M271702</link>
      <description>&lt;P&gt;Read the data as text strings and then convert it your self.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 length s1 s2 $30 timestamp_1 timestamp_2 8;
 format timestamp_1 timestamp_2 DATETIME19.;
 infile datalines; 
 input s1 s2 ;
 array s s1-s2;
 array t timestamp_1-timestamp_2 ;
 do i=1 to dim(s);
   t(i) = input(s(i),??e8601dz30.);
   if missing(t(i)) then t(i)=input(s(i),??anydtdtm30.);
 end;
 put (_all_) (=/);
datalines;
2013-07-29T11:55:21Z 2016-07-29T11:35:21Z
2014-08-04T22:12:49+02:00 2011-11-15
2018-11-1 2016-07-29T11:35:21Z
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;s1=2013-07-29T11:55:21Z
s2=2016-07-29T11:35:21Z
timestamp_1=29JUL2013:11:55:21
timestamp_2=29JUL2016:11:35:21
i=3

s1=2014-08-04T22:12:49+02:00
s2=2011-11-15
timestamp_1=04AUG2014:20:12:49
timestamp_2=15NOV2011:00:00:00
i=3

s1=2018-11-1
s2=2016-07-29T11:35:21Z
timestamp_1=01NOV2018:00:00:00
timestamp_2=29JUL2016:11:35:21
i=3&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Jan 2017 18:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328534#M271702</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-01-30T18:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to execute a different group of statements depending on which variable contains invalid valu</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328640#M271703</link>
      <description>&lt;P&gt;I think you have to reset _ERROR_=0&amp;nbsp;within&amp;nbsp;each do group.&amp;nbsp;&amp;nbsp; Otherwise all do groups subsequent to the first variable provoking an error will be executed.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 05:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-execute-a-different-group-of-statements-depending-on/m-p/328640#M271703</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-31T05:04:02Z</dc:date>
    </item>
  </channel>
</rss>

