<?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 add row number in an empty dataset in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849884#M41880</link>
    <description>&lt;P&gt;I don't really understand why it matters if the dataset has 0 or 100 observations if there is no data there.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 15:40:16 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-12-15T15:40:16Z</dc:date>
    <item>
      <title>How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849874#M41876</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an empty dataset which contains let's say var1 until var 10 plus the var n.&lt;/P&gt;
&lt;P&gt;I would like to set n from 1 to 100.&amp;nbsp; Thereafter, I will use this template to make a join with another table using n.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ex:&lt;/P&gt;
&lt;P&gt;var1 var2 ... var10 n&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do we do that task ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849874#M41876</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2022-12-15T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849876#M41877</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     length var1-var10 8;
     do n=1 to 100;
          output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849876#M41877</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-15T15:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849880#M41878</link>
      <description>In the dataset want, var1 until var10 and n already exist but there is no value in those.  &lt;BR /&gt;I have tried:&lt;BR /&gt;data want;&lt;BR /&gt;set want&lt;BR /&gt;do n=1 to 100;&lt;BR /&gt;           output;&lt;BR /&gt;end;&lt;BR /&gt;and it does not work ?  Does the fact to add the length statement solve that issue ?&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849880#M41878</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2022-12-15T15:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849883#M41879</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;In the dataset want, var1 until var10 and n already exist but there is no value in those. &lt;BR /&gt;I have tried:&lt;BR /&gt;data want;&lt;BR /&gt;set want&lt;BR /&gt;do n=1 to 100;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;and it does not work ? Does the fact to add the length statement solve that issue ?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That data step will stop at the SET statement if the input dataset is empty.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So don't actually execute the SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have;
  do n=1 to 100;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849883#M41879</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-15T15:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849884#M41880</link>
      <description>&lt;P&gt;I don't really understand why it matters if the dataset has 0 or 100 observations if there is no data there.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849884#M41880</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-15T15:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849885#M41881</link>
      <description>&lt;P&gt;So describe this empty data set to me. How many rows? A zero row empty data set is different than a 100 row data set where there are no values in any of the columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMPORTANT CONCEPT: Never say "it does not work" and then provide no other information. We don't know what you did and we don't know what happened. If something doesn't work, give us more information about what you did (the exact code) and what was wrong (errors in the log, then show us the log; or wrong output, then show us the wrong output and explain what you want).&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849885#M41881</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-15T15:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849887#M41882</link>
      <description>&lt;P&gt;How many records do you currently have in your data set? 1? 0?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would not expect the code you post to work as 1) missing ; on the SET statement so would generate an error when encountering the DO and 2) until a RUN or following data/proc statement the code doesn't execute at all.&lt;/P&gt;
&lt;PRE&gt;data want;
set want
do n=1 to 100;
output;
end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849887#M41882</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-15T15:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849890#M41883</link>
      <description>&lt;P&gt;it is a good question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;imagine that I have generated a dataset A with var1-var4 values including n, also with values in it.&lt;/P&gt;
&lt;P&gt;The I take the dataset B which contains var1 until var10 including n.&lt;/P&gt;
&lt;P&gt;In that dataset B, i want to drop (var1 to var4) and keep n as below;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data b(drop= var1 var2 var3 var4);&lt;/P&gt;
&lt;P&gt;set b;&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then create new table as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table pilote_&amp;amp;startyear2._&amp;amp;endyear2._jointure_v001 as&lt;BR /&gt;select a.*&lt;BR /&gt;,b.*&lt;BR /&gt;from work.jointure as a&lt;BR /&gt;left join pilote_&amp;amp;startyear._&amp;amp;endyear._jointure_tmpl as b on(a.n1=b.n);&lt;BR /&gt;Quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where dataset a is like jointure and dataset b is like&amp;nbsp; pilote_&amp;amp;startyear._&amp;amp;endyear._jointure_tmpl&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849890#M41883</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2022-12-15T15:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849893#M41884</link>
      <description>&lt;P&gt;Huh?&lt;/P&gt;
&lt;P&gt;Why not just merge on the key variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge a(in=in1) b;
  by n;
  if in1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then it does not matter if B has zero observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you seem to have gotten stuck on a SQL mode and so avoided the obvious solution.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849893#M41884</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-15T15:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849894#M41885</link>
      <description>&lt;P&gt;Missing semicolon on the SET statement would have an impact.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849894#M41885</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-12-15T15:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849895#M41886</link>
      <description>&lt;P&gt;Must add a STOP statement after the END statement, at a minimum to avoid the note about DATA step ending due to looping.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 16:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849895#M41886</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-12-15T16:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to add row number in an empty dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849899#M41887</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Must add a STOP statement after the END statement, at a minimum to avoid the note about DATA step ending due to looping.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or if you want the N variable to be the first one you can just run the SET statement last.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do n=1 to 3; output; end;
  set sashelp.class(obs=0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2022 16:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-add-row-number-in-an-empty-dataset/m-p/849899#M41887</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-15T16:05:46Z</dc:date>
    </item>
  </channel>
</rss>

