<?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: Appending to data set with 0 observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7859#M181</link>
    <description>Other way,&lt;BR /&gt;
&lt;BR /&gt;
data OUT ;&lt;BR /&gt;
    if nc eq 0 or eof then&lt;BR /&gt;
    do;&lt;BR /&gt;
        value=symget('mvar');&lt;BR /&gt;
        output;&lt;BR /&gt;
    end;&lt;BR /&gt;
    set INPUT nobs=nc end=eof;&lt;BR /&gt;
    output;&lt;BR /&gt;
run;</description>
    <pubDate>Fri, 23 Apr 2010 04:54:11 GMT</pubDate>
    <dc:creator>DataShare</dc:creator>
    <dc:date>2010-04-23T04:54:11Z</dc:date>
    <item>
      <title>Appending to data set with 0 observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7857#M179</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I'm trying to append a single observation containing the value of a macro variable to an existing data set. My code (see below) works fine as long my input data set contains at least one observation, but fails if not.&lt;BR /&gt;
&lt;BR /&gt;
Due to the context my program will run, I'm looking for a solution which works and &lt;BR /&gt;
- ensures that type and length of data set variable VALUE in OUT is equal to INPUT&lt;BR /&gt;
- does not need creating temporary data sets &lt;BR /&gt;
&lt;BR /&gt;
Does anyone have an idea for a simple solution? &lt;BR /&gt;
&lt;BR /&gt;
Many thanks!&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Stephan &lt;BR /&gt;
&lt;BR /&gt;
/** sas code begin *******************************************/&lt;BR /&gt;
%let mvar=test;&lt;BR /&gt;
&lt;BR /&gt;
data INPUT; /*works */&lt;BR /&gt;
length value $20;&lt;BR /&gt;
value="obs1";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data INPUT; /*works not*/&lt;BR /&gt;
length value $20;&lt;BR /&gt;
delete;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data OUT;&lt;BR /&gt;
  set INPUT end=eof;&lt;BR /&gt;
  output;&lt;BR /&gt;
  if(eof) then do;&lt;BR /&gt;
    value=symget('mvar');&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/** sas code end *******************************************/</description>
      <pubDate>Thu, 22 Apr 2010 10:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7857#M179</guid>
      <dc:creator>ssc</dc:creator>
      <dc:date>2010-04-22T10:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Appending to data set with 0 observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7858#M180</link>
      <description>[pre]&lt;BR /&gt;
%let mvar=test;&lt;BR /&gt;
&lt;BR /&gt;
data INPUT; /*works */&lt;BR /&gt;
   length value $20;&lt;BR /&gt;
   do _n_ = 1 to 10;&lt;BR /&gt;
      value="obs1";&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
data INPUT; /*works not*/&lt;BR /&gt;
   length value $20;&lt;BR /&gt;
   delete;&lt;BR /&gt;
   run;* cancel;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data OUT;&lt;BR /&gt;
   do while(not eof);&lt;BR /&gt;
      set INPUT end=eof;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   value=symget('mvar');&lt;BR /&gt;
   output;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
To make it more APPEND like where you just add data to the end MODIFY is a good choice.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data input;&lt;BR /&gt;
   if 0 then modify input;&lt;BR /&gt;
   value=symget('mvar');&lt;BR /&gt;
   output;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]

Message was edited by: data _null_;</description>
      <pubDate>Thu, 22 Apr 2010 11:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7858#M180</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-22T11:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Appending to data set with 0 observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7859#M181</link>
      <description>Other way,&lt;BR /&gt;
&lt;BR /&gt;
data OUT ;&lt;BR /&gt;
    if nc eq 0 or eof then&lt;BR /&gt;
    do;&lt;BR /&gt;
        value=symget('mvar');&lt;BR /&gt;
        output;&lt;BR /&gt;
    end;&lt;BR /&gt;
    set INPUT nobs=nc end=eof;&lt;BR /&gt;
    output;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 23 Apr 2010 04:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-to-data-set-with-0-observations/m-p/7859#M181</guid>
      <dc:creator>DataShare</dc:creator>
      <dc:date>2010-04-23T04:54:11Z</dc:date>
    </item>
  </channel>
</rss>

