<?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 generate a code from data with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896279#M354146</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i have a dataset like this:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;L0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;SI&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1M&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;and I would like to generate a code conditional on the data.&lt;/P&gt;&lt;P&gt;This is the code I would like to obtain:&lt;/P&gt;&lt;P&gt;if var3='L0' then x=0;&lt;/P&gt;&lt;P&gt;if var1='U' then x=1;&lt;/P&gt;&lt;P&gt;if var2='SI' then x=0;&lt;/P&gt;&lt;P&gt;if var1='1' and var2='50' then x=1;&lt;/P&gt;&lt;P&gt;if var4='1M' then x=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see when a variable is missing, I don't want the condition to contain it while when there is more than one not missing variables I would like a condition containing all not missing variables linked by an "and".&lt;/P&gt;&lt;P&gt;I tried with a data _null_ code without success.&lt;/P&gt;&lt;P&gt;Can you suggest me the code?&lt;/P&gt;&lt;P&gt;Any help is really appreciated.&lt;/P&gt;&lt;P&gt;Thank you very much in advance&lt;/P&gt;&lt;P&gt;F.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 15:44:27 GMT</pubDate>
    <dc:creator>Francy</dc:creator>
    <dc:date>2023-09-28T15:44:27Z</dc:date>
    <item>
      <title>generate a code from data with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896279#M354146</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;i have a dataset like this:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;L0&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;U&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;SI&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1M&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;and I would like to generate a code conditional on the data.&lt;/P&gt;&lt;P&gt;This is the code I would like to obtain:&lt;/P&gt;&lt;P&gt;if var3='L0' then x=0;&lt;/P&gt;&lt;P&gt;if var1='U' then x=1;&lt;/P&gt;&lt;P&gt;if var2='SI' then x=0;&lt;/P&gt;&lt;P&gt;if var1='1' and var2='50' then x=1;&lt;/P&gt;&lt;P&gt;if var4='1M' then x=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see when a variable is missing, I don't want the condition to contain it while when there is more than one not missing variables I would like a condition containing all not missing variables linked by an "and".&lt;/P&gt;&lt;P&gt;I tried with a data _null_ code without success.&lt;/P&gt;&lt;P&gt;Can you suggest me the code?&lt;/P&gt;&lt;P&gt;Any help is really appreciated.&lt;/P&gt;&lt;P&gt;Thank you very much in advance&lt;/P&gt;&lt;P&gt;F.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 15:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896279#M354146</guid>
      <dc:creator>Francy</dc:creator>
      <dc:date>2023-09-28T15:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: generate a code from data with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896284#M354148</link>
      <description>&lt;P&gt;A simple REPORT WRITING problem.&amp;nbsp; Where the REPORT you want to write is SAS CODE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data metadata ;
  infile cards dsd dlm='|' truncover;
  input (var1-var4) (:$8.) x ;
cards;
 |  |L0|  |0
U|  |  |  |1
 |SI|  |  |0
1|50|  |  |1
 |  |  |1M|0
 ;

filename code temp;
data _null_;
  file code;
  set metadata ;
  array var var1-var4 ;
  length name $32 sep $3 ;
  sep='if';
  do index=1 to dim(var);
    if not missing(var[index]) then do;
       name=vname(var[index]);
       put sep name '=' var[index] :$quote. @ ;
       sep='and' ;
    end;
  end;
  put 'then ' x= ';' ;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will generate code like:&lt;/P&gt;
&lt;PRE&gt;if var3 ="L0" then x=0 ;
if var1 ="U" then x=1 ;
if var2 ="SI" then x=0 ;
if var1 ="1" and var2 ="50" then x=1 ;
if var4 ="1M" then x=0 ;
&lt;/PRE&gt;
&lt;P&gt;which you could then use in a data step (or anywhere you can use IF/THEN statements) by using&amp;nbsp; %INCLUDE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the result of that series of IF/THEN statements is that the last one that is satisfied will "WIN".&amp;nbsp; If that is not what you wanted then you might need to re-order the metadata file. Or generate more complex code.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 16:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896284#M354148</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-28T16:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: generate a code from data with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896379#M354183</link>
      <description>Great!&lt;BR /&gt;Thank you for the code Tom</description>
      <pubDate>Fri, 29 Sep 2023 08:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-code-from-data-with-missing-values/m-p/896379#M354183</guid>
      <dc:creator>Francy</dc:creator>
      <dc:date>2023-09-29T08:01:11Z</dc:date>
    </item>
  </channel>
</rss>

