<?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 do a dynamic condition based on variable value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589542#M168641</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data demo;
Set have end = eof;

If _n_=1 then do;
Call execute(‘data want; set have;’);
End;

Call execute (‘Value = ‘||cdn||’;’);

If eof then call execute(‘run’j;

Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you want as output? The T/F or 0/1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute and dosubl are probably what you’ll need here. Resolve could also be an option but not sure.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259318"&gt;@Coooooo_Lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datasets like below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32549i396A2CD36CC8C708/image-size/large?v=v2&amp;amp;px=999" role="button" title="a.png" alt="a.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each row, I want to check if the condition (variable CON) was met or not.&lt;BR /&gt;As you see, for different test the condition is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here just part of data, it may have more than 100 different and conditions.&lt;/P&gt;
&lt;P&gt;How should I structure a dynamic code to check each row based on the value of each CON?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2019 07:25:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-09-18T07:25:01Z</dc:date>
    <item>
      <title>How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589533#M168640</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a datasets like below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32549i396A2CD36CC8C708/image-size/large?v=v2&amp;amp;px=999" role="button" title="a.png" alt="a.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each row, I want to check if the condition (variable CON) was met or not.&lt;BR /&gt;As you see, for different test the condition is different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here just part of data, it may have more than 100 different and conditions.&lt;/P&gt;&lt;P&gt;How should I structure a dynamic code to check each row based on the value of each CON?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 06:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589533#M168640</guid>
      <dc:creator>Coooooo_Lee</dc:creator>
      <dc:date>2019-09-18T06:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589542#M168641</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data demo;
Set have end = eof;

If _n_=1 then do;
Call execute(‘data want; set have;’);
End;

Call execute (‘Value = ‘||cdn||’;’);

If eof then call execute(‘run’j;

Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you want as output? The T/F or 0/1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute and dosubl are probably what you’ll need here. Resolve could also be an option but not sure.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259318"&gt;@Coooooo_Lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datasets like below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="a.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32549i396A2CD36CC8C708/image-size/large?v=v2&amp;amp;px=999" role="button" title="a.png" alt="a.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each row, I want to check if the condition (variable CON) was met or not.&lt;BR /&gt;As you see, for different test the condition is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here just part of data, it may have more than 100 different and conditions.&lt;/P&gt;
&lt;P&gt;How should I structure a dynamic code to check each row based on the value of each CON?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 07:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589542#M168641</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-18T07:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589544#M168642</link>
      <description>&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the quick reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to have a dataset, which means if the condition was met then I can set a flag as 1, else flag=0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding below code, I think the second should be updated, right?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Call execute (‘Value = ‘||cdn||’;’);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A little bit confused by &amp;nbsp;‘||cdn||’&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 07:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589544#M168642</guid>
      <dc:creator>Coooooo_Lee</dc:creator>
      <dc:date>2019-09-18T07:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589545#M168643</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;As you see, for different test the condition is different.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No they're not.&amp;nbsp; Obs 8-13 have the same ID, TEST, and CON.&amp;nbsp; You have non-unique combinations of ID, TEST, and CON throughout your screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMO, you should store the &lt;STRONG&gt;&lt;U&gt;unique&lt;/U&gt;&lt;/STRONG&gt; test conditions in one dataset, and the test results (this dataset) as a separate dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My %loop_control macro may help here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop_control.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you only supplied a screenshot rather than example code, I can only provide dummy code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%let id=%trim(&amp;amp;id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%let test=%trim(&amp;amp;test);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%let con=%trim(&amp;amp;con);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;data my_results;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set my_input;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if &amp;amp;con;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;title1 "ID: &amp;amp;id";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;title2 "TEST: &amp;amp;test";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;proc print data=my_results;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;title;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%loop_control(control=&amp;lt;your unnamed dataset from your screenshot&amp;gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the macro header for more use cases.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 07:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589545#M168643</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-09-18T07:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589550#M168646</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259318"&gt;@Coooooo_Lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the quick reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to have a dataset, which means if the condition was met then I can set a flag as 1, else flag=0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding below code, I think the second should be updated, right?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Call execute (‘Value = ‘||cdn||’;’);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A little bit confused by &amp;nbsp;‘||cdn||’&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;|| is a concatenation operator so the argument of call execute is the concatenation of strings :&lt;/P&gt;
&lt;P&gt;- 'Value=',&lt;/P&gt;
&lt;P&gt;- cdn,&lt;/P&gt;
&lt;P&gt;- ';'&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/13879"&gt;@Reeza&lt;/a&gt;'s code will create a dataset with a new column 'Value' that corresponds to the flag you want to compute.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 07:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589550#M168646</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-09-18T07:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589552#M168647</link>
      <description>&lt;P&gt;How about this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cats('when(',quote(trim(con),"'"),') check=(',con,')') into :check separated by ';' from have;
run;

data want;
  set have;
  select(con);
    &amp;amp;check;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2019 08:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589552#M168647</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-09-18T08:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589553#M168648</link>
      <description>&lt;P&gt;Here is a &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Dosubl&lt;/A&gt; approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id test $ con :$100. chg pchg aval;
infile datalines dlm=',';
datalines;
2001,E,PCHG &amp;lt;= -50,-8,-20.05012531,31.9
2001,I,CHG &amp;lt;= -2 and AVAL in (0 1),0,0,3
;

data want(drop=i rc);
    do i=1 to nobs;
       set have nobs=nobs;
       rc=dosubl(compbl(cat("
          data _null_; 
             n=", i, "; 
             set have point=n; 
             x=(", con, ");
             call symputx('flag', x);
             stop;
          run;")));
       flag=input(symget('flag'), 8.);
       output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2019 08:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589553#M168648</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-18T08:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589554#M168649</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess something run here, I tested your code.&lt;/P&gt;&lt;P&gt;The log file shows like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 + data want; set x;&lt;BR /&gt;2 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;3 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;4 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;5 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;6 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;7 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;8 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;9 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;10 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;11 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;12 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;13 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;14 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;15 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;16 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;17 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;18 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;19 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;20 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;21 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;22 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;23 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;24 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;25 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;26 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;27 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;28 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;29 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;30 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;31 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;32 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;33 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;34 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;35 + if CHG &amp;lt;= -4 then fl="Y"; else fl="N";&lt;BR /&gt;36 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;37 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;38 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;39 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;40 + if PCHG &amp;lt;= -50 then fl="Y"; else fl="N";&lt;BR /&gt;41 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;42 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;43 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;BR /&gt;44 + if CHG &amp;lt;= -2 and AVAL in (0 1) then fl="Y"; else fl="N";&lt;/P&gt;&lt;P&gt;45 + run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for each row, only the last logic would be checked.&lt;BR /&gt;What I want is check each condition on each row, which means checking PCHG &amp;lt;= -50 for the first row and&amp;nbsp;CHG &amp;lt;= -2 and AVAL in (0 1) for the second row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 08:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589554#M168649</guid>
      <dc:creator>Coooooo_Lee</dc:creator>
      <dc:date>2019-09-18T08:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589589#M168671</link>
      <description>&lt;P&gt;Reeza's code could change into :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id test $ con :$100. chg pchg aval;
infile datalines dlm=',';
datalines;
2001,E,PCHG &amp;lt;= -50,-8,-20.05012531,31.9
2001,I,CHG &amp;lt;= -2 and AVAL in (0 1),0,0,3
;
data _null_;
 set have end=last;
 if _n_=1 then call execute('data want;set have;');
 call execute(catt('if _n_=',_n_,' then flag=(',con,');'));
 if last then call execute('run;');
  else call execute('else ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2019 11:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589589#M168671</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-18T11:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589666#M168689</link>
      <description>&lt;P&gt;I think &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s suggestion is the most appropriate for reasonably small number of rows.&amp;nbsp; But for N=1,000,000, there will be an average of 500,000 IF tests per observation -- even if you might only have, say, 100 unique CON expressions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case, it's better to construct something like;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; select (con);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ("x&amp;gt;1")&amp;nbsp;&amp;nbsp; flag=(x&amp;gt;1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ("chg*x&amp;gt;3") flag=(chg*x&amp;gt;3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do that by writing to a temporary ascii file holding code such as my example above and then %INCLUDE it in a "data want;" step, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
filename tmp clear;
filename tmp temp;
data _null_;
  if 0 then set have (keep=con);
  declare hash h (dataset:'have (keep=con)');
    h.definekey('con');
    h.definedata('con');
    h.definedone();
  declare hiter hi ('h');
  file tmp;
  do rc=hi.first() by 0 until (hi.next()^=0);
    put '  when ('  con $quote. ') flag=(' con ');' ;
  end;
run;
data want;
  set have ;
  select (con);
  %include tmp /source2;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The key to the above is the creation of a hash object with CON as its key.&amp;nbsp; The object will default to one item in the object per unique key.&amp;nbsp; The program&amp;nbsp;constructs such an object (named H), and then iterates through it to write out code as I posted above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are uncomfortable using hash object, then you can use a sorted (by CON) dataset, as here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have (keep=con) out=sorted_con nodupkey;
  by con;
run;

filename tmp temp;
data _null_;
  set sorted_con;
  file tmp;
  put '  when ('  con $quote. ') flag=(' con ');' ;
run;

data want;
  set have;
  select (con);
  %include tmp / source2;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, this is beneficial (in terms of performance speed) only when the cardinality of CON values is significantly smaller (maybe ration of 1/10 or so?)&amp;nbsp;than the number of observations in HAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In both case, you would be using a DATA _NULL_ step, which allow you to SET a dataset, but not bother writing out a sas dataset.&amp;nbsp; And that's what you want, because the purpose here is to write out all the "when (...) flag=(...):" statements to an ascii file.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 14:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589666#M168689</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-09-18T14:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589856#M168764</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259318"&gt;@Coooooo_Lee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the quick reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to have a dataset, which means if the condition was met then I can set a flag as 1, else flag=0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;You weren't clear in your original post how you wanted to process your conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all you want to do is set a boolean flag perhaps this approach will work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;BR /&gt;&lt;BR /&gt;data tests;
   length con $100;
   infile datalines truncover;
   input con $100.;
   datalines4;
flag1 = (statecode = 'FL')
flag2 = (90000 &amp;lt;= zip &amp;lt;= 99999)
flag3 = (not missing(alias_city))
;;;;
run;

%macro code;
&amp;amp;con;
%mend;

data results;
   format flag1 flag2 flag3;  * set PDV order ;
   set sashelp.zipcode;
   %loop_control(control=tests)
run;

data flags;
   set results;
   if sum(of flag:) &amp;gt; 0;
   keep flag: statecode zip alias_city;
run;

%macro code;
%let num=&amp;amp;word;
data flag&amp;amp;num;
   set results;
   if flag&amp;amp;num=1;
   keep flag&amp;amp;num statecode zip alias_city;
run;
%mend;
%loop(1 2 3)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2019 22:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589856#M168764</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-09-18T22:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a dynamic condition based on variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589887#M168777</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;A fine solution, provided that the distinct conditions aren't numerous enough to make the value of CHECK exceed the maximum allowable macro variable length.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 02:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-dynamic-condition-based-on-variable-value/m-p/589887#M168777</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-19T02:08:32Z</dc:date>
    </item>
  </channel>
</rss>

