<?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: where condition not satified in a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301740#M63910</link>
    <description>&lt;P&gt;You could begin the DATA step this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;if 0 then set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition 0 is always false, so this extra SET statement never executes. &amp;nbsp;However, it serves a purpose by defining your variables so that you can define the array as you originally intended. &amp;nbsp;(Also note, the variable list would be _numeric_, not _numeric.)&lt;/P&gt;</description>
    <pubDate>Fri, 30 Sep 2016 11:21:40 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-09-30T11:21:40Z</dc:date>
    <item>
      <title>where condition not satified in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301725#M63905</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to write a macro that takes an id as parameter and display the columns&lt;/P&gt;
&lt;P&gt;of a dataset for the (unique) row having that id. If there is no observation for the given id,&lt;/P&gt;
&lt;P&gt;i want to display the columns anyway with missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simplified example of what i tried&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id 1. x 2.;
cards;
112
25
326
421
516
64
run;

%macro display_cols;

    array columns (*) _NUMERIC;

    do i=1 to dim(columns);
        put vname(columns(i))=;
    end;

%mend display_cols;

%macro infos_id(id);

    data _NULL_;

        /* If the id is not in the table, we display the columns anyway */
        if eof and id=. then do;

            id=&amp;amp;id;
            output;
            %display_cols;

        end;

        set have end=eof;
        where id=&amp;amp;id.;

        %display_cols;

    run;

%mend infos_id;

%infos_id(2);

%infos_id(8);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log shows the following message :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 124-185: The variable columns has already been defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i comment the second %display_cols and test with a non-existing id, the columns displayed&lt;/P&gt;
&lt;P&gt;are id and eof instead of id and x. I understand that it is because the "output" is before the "set have"&lt;/P&gt;
&lt;P&gt;but i can't see how it can be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to take advantage of the table structure to avoid explicitely listing all the columns&lt;/P&gt;
&lt;P&gt;in case of a non-existing id ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 10:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301725#M63905</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-09-30T10:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: where condition not satified in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301727#M63906</link>
      <description>&lt;P&gt;You have a statement defining an array in your macro. Array definitions shall only appear once for each array in the data step. So take it out of the macro and write it into the data step.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 10:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301727#M63906</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-30T10:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: where condition not satified in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301729#M63907</link>
      <description>&lt;P&gt;The names of columns can easily be displayed by querying sashelp.vcolumn (data/proc step) or dictionary.columns (SQL).&lt;/P&gt;
&lt;P&gt;Names of columns stay the same over all rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output statement in a data _null_ is perfectly useless, as there is no dataset to output to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I STRONGLY recommend to try everything in a pure data step first, and only after that gets you the desired result, start wrapping into a macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the array definition does not work before the set statement, you won't be able to solve this in the way you intended.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A possible solution might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=8;
data _NULL_;
if eof and id = . then do;
  id=&amp;amp;id;
  put _all_;
  stop;
end;
else do;
set have (where=(id=&amp;amp;id.)) end=eof;
  put _all_;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 10:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301729#M63907</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-30T10:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: where condition not satified in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301733#M63909</link>
      <description>&lt;P&gt;Thank you for your answers and advises.&lt;/P&gt;
&lt;P&gt;You are right about the ouptut statement which has no use here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My example is a simplification of what i a m trying to achieve.&lt;/P&gt;
&lt;P&gt;The macro will actually write html to the output stream and&lt;/P&gt;
&lt;P&gt;the table columns are displayed in a html table so I need to&lt;/P&gt;
&lt;P&gt;process each column individually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought about dictionary.columns but tried to achieve the result this way&lt;/P&gt;
&lt;P&gt;for the sake of conciseness.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You tell me that this is impossible because the set statement must preceed&lt;/P&gt;
&lt;P&gt;any array declarations. This is what I wanted to know so i will follow your advice and use&lt;/P&gt;
&lt;P&gt;dictionary.columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 10:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301733#M63909</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-09-30T10:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: where condition not satified in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301740#M63910</link>
      <description>&lt;P&gt;You could begin the DATA step this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;if 0 then set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition 0 is always false, so this extra SET statement never executes. &amp;nbsp;However, it serves a purpose by defining your variables so that you can define the array as you originally intended. &amp;nbsp;(Also note, the variable list would be _numeric_, not _numeric.)&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2016 11:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301740#M63910</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-30T11:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: where condition not satified in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301741#M63911</link>
      <description>Great trick, thank you very much !&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Sep 2016 11:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-condition-not-satified-in-a-data-step/m-p/301741#M63911</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-09-30T11:44:49Z</dc:date>
    </item>
  </channel>
</rss>

