<?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: Wha'ts the best way to add and populate the row number into thousand of existing datasets in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936986#M45061</link>
    <description>Last question:   In a library, it is possible to trace only the spde file using proc contents and if so which variable and value.</description>
    <pubDate>Wed, 24 Jul 2024 14:39:56 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2024-07-24T14:39:56Z</dc:date>
    <item>
      <title>Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936755#M45050</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know, what's the best way to add the variable rownumber = _n_ and to populate this variable in thousand of existing dataset.&lt;/P&gt;
&lt;P&gt;I could use something similar to that snippet:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
rowNo = _N_;
set sashelp.class;
run;

so, 

libname dest1 spde 'path1/co/...';
libname src1 spde 'path1/co/...';

data dest1.fnamex;
rowNo=_N_;
set src1.fnamex;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do a file listing and use that information to make a call execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have more efficient way to do that, please let me know&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2024 13:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936755#M45050</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-23T13:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936760#M45051</link>
      <description>&lt;P&gt;I would say the "best" way is to first answer why do thousands of existing datasets need to be replaced this way?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2024 13:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936760#M45051</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-23T13:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936805#M45053</link>
      <description>&lt;P&gt;Let's suspend judgement of whether this is a wise thing to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way is to get the list of IN/OUT pairs in a dataset and use it to generate the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you just want to copy every dataset in libref SRC1 to the libref DEST1 then you could use a simple PROC CONTENTS to get the list of datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your program could look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname dest1 spde 'path1/co/...';
libname src1 spde 'path1/co/...';

proc contents data=src1._all_ noprint out=contents; run;
filename code temp;
data _null_;
  set contents;
  by memname;
  if first.memname;
  put 'data dest1.' memname ';'
    / 'rowNo=_N_;'
    / 'set src1.' memname ';'
    / 'run;'
  ;
run;

%include code / source2;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2024 15:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936805#M45053</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-23T15:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936968#M45054</link>
      <description>&lt;P&gt;it is a good question.&amp;nbsp; Due to a new legislation, we need to remove policies transactions from the original dataset when the policies is older than 10 years. So if in a dataset, we have policies older than 10 years, their transactions need to be remove from the original dataset and put into another dataset, where some information about those policies will be depersonalized.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So we need to add the rownumber into the original dataset to keep the original observations rownumber either into the new dataset (observations removed) and the depersonalized dataset (observations removed from the original dataset) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the example below with sashelp.class&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class_original;
rownum=_N_;
set sashelp.class;
run;

/* suffix dpds= depersonnalized dataset */

data class class_dpds;
set class_original;
if rownum in (1,5,10,15) then 
do;
	Name='';
	output class_dpds;
end;
else
output class;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2024 13:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936968#M45054</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-24T13:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936973#M45055</link>
      <description>&lt;P&gt;You SAS code seems very interesting but I have made a test with sashelp and it is not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname dest1 %sysfunc(quote(%sysfunc(pathname(work))));


proc contents data=sashelp._all_ noprint out=contents; run;
filename code temp;
data _null_;
  set contents;
  by memname;
  if first.memname;
  put 'data dest1.' memname ';'
    / 'rowNo=_N_;'
    / 'set sashelp.' memname ';'
    / 'run;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Could you please provide an example with sashelp&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936973#M45055</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-24T14:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936981#M45058</link>
      <description>&lt;P&gt;Works fine for me.&amp;nbsp; Example processing just the first 4 datasets found.&lt;/P&gt;
&lt;PRE&gt;1    proc contents data=sashelp._all_ noprint out=contents;run;

NOTE: The data set WORK.CONTENTS has 17124 observations and 41 variables.
NOTE: PROCEDURE CONTENTS used (Total process time):
      real time           0.16 seconds
      cpu time            0.17 seconds


2    filename code temp;
3    data _null_;
4      set contents ;
5      by memname;
6      if first.memname;
7      dsn+1;
8      if dsn&amp;gt;3 then stop;
9      file code;
10     put 'data work.' memname ';'
11       / 'rownum+1;'
12       / 'set sashelp.' memname ';'
13       / 'run;'
14     ;
15   run;

NOTE: The file CODE is:
      (system-specific pathname),
      (system-specific file attributes)

NOTE: 12 records were written to the file (system-specific pathname).
      The minimum record length was 4.
      The maximum record length was 20.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


16   %include code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is (system-specific pathname).
17  +data work.AACOMP ;
18  +rownum+1;
19  +set sashelp.AACOMP ;
20  +run;

NOTE: The data set WORK.AACOMP has 2020 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


21  +data work.AARFM ;
22  +rownum+1;
23  +set sashelp.AARFM ;
24  +run;

NOTE: The data set WORK.AARFM has 130 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


25  +data work.ADSMSG ;
26  +rownum+1;
27  +set sashelp.ADSMSG ;
28  +run;

NOTE: The data set WORK.ADSMSG has 426 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: %INCLUDE (level 1) ending.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936981#M45058</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-24T14:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936983#M45059</link>
      <description>file code is not present into your data _null_ ..... run;  portion of your sas code.  It is why it was not working</description>
      <pubDate>Wed, 24 Jul 2024 14:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936983#M45059</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-24T14:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936984#M45060</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;file code is not present into your data _null_ ..... run; portion of your sas code. It is why it was not working&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; The data step will know you want to write to a file unless you tell it.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936984#M45060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-24T14:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936986#M45061</link>
      <description>Last question:   In a library, it is possible to trace only the spde file using proc contents and if so which variable and value.</description>
      <pubDate>Wed, 24 Jul 2024 14:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936986#M45061</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-24T14:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936988#M45062</link>
      <description>&lt;P&gt;I library (really a libref) only has one engine.&amp;nbsp; You should be able to tell the SPDE librefs by looking at the ENGINE variable in the PROC CONTENTS output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now a directory on the disk can have multiple types of files.&amp;nbsp; You can use SAS version 6 and SAS version 7 (the current format) in the same directory, but the engine being used by the libref will determine which files SAS actually "sees" with that libref.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936988#M45062</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-24T14:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Wha'ts the best way to add and populate the row number into thousand of existing datasets</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936991#M45063</link>
      <description>&lt;P&gt;Add "file code;" before&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;if first.memname;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2024 14:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Wha-ts-the-best-way-to-add-and-populate-the-row-number-into/m-p/936991#M45063</guid>
      <dc:creator>verdantsphinx</dc:creator>
      <dc:date>2024-07-24T14:46:20Z</dc:date>
    </item>
  </channel>
</rss>

