<?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 get observation when variable does not exist in Advanced Programming</title>
    <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711100#M37</link>
    <description>&lt;P&gt;So you want to create theh variable D only if the variable C does not exist?&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2021 14:06:58 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-01-13T14:06:58Z</dc:date>
    <item>
      <title>How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711093#M36</link>
      <description>&lt;P&gt;Hi Reader,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me with below mentioned data where Variable C does not exist in dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need to create D variable where a = "One" and Variable C is null/not exist then consider b variable data.&lt;/P&gt;
&lt;DIV id="tinyMceEditorpdhokriya_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;Output would be like this : -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;a&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;b&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;d&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;One&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;New1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;New1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Two&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;New2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;New2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Three&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;New3&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;New3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Priyanka&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711093#M36</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-01-13T14:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711100#M37</link>
      <description>&lt;P&gt;So you want to create theh variable D only if the variable C does not exist?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711100#M37</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-13T14:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711101#M38</link>
      <description>&lt;P&gt;There is no variable c in your dataset, so it can't be used in a condition. It "can't even be null".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to make code conditional upon the mere &lt;EM&gt;presence&lt;/EM&gt; of a variable in a dataset, query DICTIONARY.COLUMNS and run code conditionally (%IF-%THEN-%DO-%END).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name=X;

proc sql noprint;
select name into :name
from dictionary.columns
where libname ="WORK" and memname = "HAVE" and upcase(name) = "C";
quit;

data want;
set have;
%if &amp;amp;name. = X
%then do;
if a = "One" then d = b;
%end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711101#M38</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-13T14:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711110#M39</link>
      <description>&lt;P&gt;I am a bit unclear. The C column does not exist at all, so you can't use it in a condition.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711110#M39</guid>
      <dc:creator>Panagiotis</dc:creator>
      <dc:date>2021-01-13T14:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711118#M40</link>
      <description>&lt;P&gt;Next code will do what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
        retain c;  /* if c does not exist it will be added with null value */
        if a='One' then do;&lt;BR /&gt;           if missing(c) then d=b;
           else d=c;&lt;BR /&gt;        end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jan 2021 14:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711118#M40</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-13T14:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711234#M41</link>
      <description>&lt;P&gt;This will give &lt;U&gt;Note: Variable c is uninitialized&lt;/U&gt;. Which will not be recommended.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711234#M41</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-01-13T17:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711236#M42</link>
      <description>&lt;P&gt;If C does not exits thn only i will move to b. else will consider C data only.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 17:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711236#M42</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-01-13T17:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711244#M43</link>
      <description>&lt;P&gt;Taking&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;code and updated to this should give you&amp;nbsp; what you need. Variable d=b when c is either missing from the table or it's value is missing.&lt;/P&gt;
&lt;P&gt;%let name=X;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select name into :name&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname ="WORK" and memname = "HAVE" and upcase(name) = "C";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;%if &amp;amp;name = X &lt;BR /&gt;%then %do;&lt;BR /&gt;d = b;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;if c=" " then d=b;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 18:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711244#M43</guid>
      <dc:creator>SuCheeTay</dc:creator>
      <dc:date>2021-01-13T18:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711245#M44</link>
      <description>&lt;P&gt;Alternative way to check weather variable C exists:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;
   dsid = open('have');  /*open file to check */
   if dsid then do;
      _varnum = varnum(dsid,'C');   /* check does C exist */
      putlog _varnum=;
   end;
   dsid = close(dsid);
run;
/***  
    _varnum = 0 for non existing C variable in HAVE dataset
    otherwise _varnum &amp;gt; 0
***/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Jan 2021 18:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711245#M44</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-13T18:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711617#M45</link>
      <description>Thank you for the solution, but I can except only 1 solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 15 Jan 2021 08:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711617#M45</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-01-15T08:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711618#M46</link>
      <description>Thank you for your help. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; AZURITE</description>
      <pubDate>Fri, 15 Jan 2021 08:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711618#M46</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-01-15T08:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get observation when variable does not exist</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711619#M47</link>
      <description>Thank you so much.</description>
      <pubDate>Fri, 15 Jan 2021 08:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/How-to-get-observation-when-variable-does-not-exist/m-p/711619#M47</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2021-01-15T08:26:43Z</dc:date>
    </item>
  </channel>
</rss>

