<?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: Can we use a condition for multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231450#M42089</link>
    <description>&lt;P&gt;Nbonda, there is another way where it is very simple.&lt;/P&gt;
&lt;P&gt;Create a macro where store all the column names that contains "date" with dictionary tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SASHELP.VCOLUMN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    select name into: all_date_columns separated by " and " from sashelp.vcolumn
    where memname = "The name of your table" and name contains "date";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The use this macro in the condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a code to this exactly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input id  _id _id1 var_id;
  cards;
1 2 3 4
; 
run;

proc sql;
    select name into: all_date_columns separated by " and " from sashelp.vcolumn
    where memname = "TEST" and name contains "id" and libname = "WORK";
quit; 

data test2;
  set test;
  if &amp;amp;all_date_columns. &amp;lt;= 4 then n_var=10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Att&lt;/P&gt;</description>
    <pubDate>Fri, 23 Oct 2015 20:40:00 GMT</pubDate>
    <dc:creator>DartRodrigo</dc:creator>
    <dc:date>2015-10-23T20:40:00Z</dc:date>
    <item>
      <title>Can we use a condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231335#M42070</link>
      <description>&lt;P&gt;How Can I use same conditon for multiple variable?&lt;/P&gt;
&lt;P&gt;lets say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;infile cards delimiter=',' dsd;&lt;/P&gt;
&lt;P&gt;input &amp;nbsp; &amp;nbsp; inv $ Date1 &lt;FONT color="#FF0000"&gt;mdyampm.&lt;/FONT&gt; Date2 &lt;FONT color="#FF0000"&gt;mdyampm.&lt;/FONT&gt; Date3 &lt;FONT color="#FF0000"&gt;mdyampm.&lt;/FONT&gt; Date4 &lt;FONT color="#FF0000"&gt;mdyampm.&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;cards ;&lt;/P&gt;
&lt;P&gt;101,09/11/2014 10:22:00 AM,02/02/1900 10:22:00 PM,10/1/2014 11:22:00 AM,9/11/2014 02:22:50 AM&lt;/P&gt;
&lt;P&gt;102,09/01/2014 10:21:00 AM,02/02/1900 10:22:00 PM,10/1/1900 12:19:00 AM,9/11/1900 12:22:50 AM&lt;/P&gt;
&lt;P&gt;103,10/11/1900 10:02:00 AM,12/02/1900 10:29:09 PM,10/1/2014 11:22:00 AM,9/11/2014 02:23:10 AM&lt;/P&gt;
&lt;P&gt;;run;&lt;/P&gt;
&lt;P&gt;data test2;&lt;/P&gt;
&lt;P&gt;set test;&lt;/P&gt;
&lt;P&gt;if date1 &amp;lt;= '1/1/1900'd then date2=.;&lt;/P&gt;
&lt;P&gt;if date2 &amp;lt;= '1/1/1900'd then date2=.;&lt;/P&gt;
&lt;P&gt;if date3 &amp;lt;= '1/1/1900'd then date2=.;&lt;/P&gt;
&lt;P&gt;if date4 &amp;lt;= '1/1/1900'd then date2=.;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there any way I can write same codition to multiple datetime variable in single line, actually I have more date variables in my task&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;Any suggestionon FORMAT to get values like ,2/09/2015 20:22:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 13:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231335#M42070</guid>
      <dc:creator>nbonda</dc:creator>
      <dc:date>2015-10-23T13:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use a condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231339#M42071</link>
      <description>&lt;P&gt;Looks like you could just:&lt;/P&gt;&lt;PRE&gt;if datepart(min(of date1-date4)) &amp;lt;= '1jan1900'd then date2=.;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2015 13:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231339#M42071</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-10-23T13:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use a condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231340#M42072</link>
      <description>&lt;P&gt;Hi mate,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes there is and it is very easy by setting a %do loop to store the number of your date columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines4;
input ID$     VISIT     value1     value2     value3;
datalines4;
A     1     5     7     9
A     2     .     .      .
A     3     .     .       .
A     4     10     5     3
A     5     .     .      .
B     1     11     2     6
B     2     .      .     . 
B     3     16     7     9
B     4     .      .     . 
B     5     18     20     5
;;;;;;
run;
%macro date(num);
data want;
set have;
  %do i =1 %to 3;
    if value&amp;amp;&amp;amp;i. = . then value&amp;amp;&amp;amp;i.=0;
  %end;
run;
%mend;
%date(3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run this code to see the syntax an to understand how it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Att&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 13:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231340#M42072</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-23T13:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use a condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231342#M42073</link>
      <description>&lt;P&gt;Yes, its called array processing. &amp;nbsp;Its good to see that your variables are prefix with a suffix number, this is good forma and makes working with the data easier. &amp;nbsp;Try something along the lines of:&lt;/P&gt;
&lt;PRE&gt;data test;&lt;BR /&gt; inv=101; Date1="09NOV2014 10:22"dt; date2="02FEB1900 19:00"dt; date3="01JAN1890 11:22"DT; date4="09NOV2014 02:22"dt; &lt;BR /&gt; format date1-date4 datetime.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want (drop=i);&lt;BR /&gt; set test;&lt;BR /&gt; array date{*} date:;&lt;BR /&gt; do i=1 to dim(date);&lt;BR /&gt;   if datepart(date{i}) &amp;lt;= "01JAN1900"d then date{2}=.;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Note that this logic will mean if any of those dates are less than or equal to 01Jan1900 then the second date will be .&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 13:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231342#M42073</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-23T13:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use a condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231447#M42088</link>
      <description>Thank you. In some of my files date variable name may be like created_date, Modified_date, date_lastupdated like that. It may not be suffixed with consecutive numbers.</description>
      <pubDate>Fri, 23 Oct 2015 20:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231447#M42088</guid>
      <dc:creator>nbonda</dc:creator>
      <dc:date>2015-10-23T20:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use a condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231450#M42089</link>
      <description>&lt;P&gt;Nbonda, there is another way where it is very simple.&lt;/P&gt;
&lt;P&gt;Create a macro where store all the column names that contains "date" with dictionary tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SASHELP.VCOLUMN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    select name into: all_date_columns separated by " and " from sashelp.vcolumn
    where memname = "The name of your table" and name contains "date";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The use this macro in the condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a code to this exactly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input id  _id _id1 var_id;
  cards;
1 2 3 4
; 
run;

proc sql;
    select name into: all_date_columns separated by " and " from sashelp.vcolumn
    where memname = "TEST" and name contains "id" and libname = "WORK";
quit; 

data test2;
  set test;
  if &amp;amp;all_date_columns. &amp;lt;= 4 then n_var=10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Att&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 20:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-a-condition-for-multiple-variables/m-p/231450#M42089</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-23T20:40:00Z</dc:date>
    </item>
  </channel>
</rss>

