<?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: renaming datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72123#M15561</link>
    <description>Or if you know you have no overlaps:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro rename_ds(order);&lt;BR /&gt;
  %local i;&lt;BR /&gt;
  proc datasets nolist;   &lt;BR /&gt;
  %do i=1 %to %sysfunc(countw(&amp;amp;order));&lt;BR /&gt;
  change data&amp;amp;i=____&amp;amp;i ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %do i=1 %to %sysfunc(countw(&amp;amp;order));&lt;BR /&gt;
  change ____&amp;amp;i=data%scan(&amp;amp;order,&amp;amp;i) ;&lt;BR /&gt;
  %end;           &lt;BR /&gt;
  quit;&lt;BR /&gt;
%mend rename_ds;&lt;BR /&gt;
&lt;BR /&gt;
%rename_ds(2 3 4 1)&lt;BR /&gt;
[pre]</description>
    <pubDate>Thu, 16 Sep 2010 23:44:14 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2010-09-16T23:44:14Z</dc:date>
    <item>
      <title>renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72117#M15555</link>
      <description>Hello all-&lt;BR /&gt;
&lt;BR /&gt;
lets say I have 5 data sets, data1, data2, ... , data5 and I also have a 5 dimensional vector x=(3,5,6,7,9).&lt;BR /&gt;
&lt;BR /&gt;
Is it possible to rename my data sets according to the numbers in my x vector? So I would get data3, data5, data6, etc. I'm sure I can do with with a macro but dont know how to proceed. &lt;BR /&gt;
&lt;BR /&gt;
George</description>
      <pubDate>Tue, 14 Sep 2010 18:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72117#M15555</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-14T18:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72118#M15556</link>
      <description>Can you share what you are trying to achieve?</description>
      <pubDate>Tue, 14 Sep 2010 19:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72118#M15556</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-09-14T19:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72119#M15557</link>
      <description>I am using the rci option in proc mixed to give me the inverse choleski matrix of each subject used in proc mixed. &lt;BR /&gt;
&lt;BR /&gt;
So for example if i use subjects 3,5,6,7, and 10 to run the analysis then rci=1 would give me the matrix of the first subject used (in this case subject 3), rci=2 would be the second subject (in this case subject 5), etc,&lt;BR /&gt;
&lt;BR /&gt;
so in proc mixed when i specify:&lt;BR /&gt;
&lt;B&gt;proc mixed;&lt;BR /&gt;
model .....  / rci=1 to 5;&lt;BR /&gt;
repeated ... / ....;&lt;BR /&gt;
ods output InvCholR(match_all)=data1;&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
the ods output will create data1,data2,...,data5 which are the 5 matrices. I just want to rename the matrices to coincide with the actual subject numbers (in this case 3,5,6,...)&lt;BR /&gt;
&lt;BR /&gt;
i found i can use&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;proc datasets;&lt;BR /&gt;
change data1=data3;&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
to rename data1 to data3. now i need to know how to run a macro that would take the data set and rename it. something like;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;%macro rename (numb_subj,ind);&lt;BR /&gt;
do i=1 to numb_subj;&lt;BR /&gt;
proc datasets;&lt;BR /&gt;
change data&amp;amp;i=data&amp;amp;ind[&amp;amp;i];&lt;BR /&gt;
run;&lt;BR /&gt;
end;&lt;BR /&gt;
%mend rename&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
where ind is the index of subject numbers, for this example ind=(3,5,6,7,10)</description>
      <pubDate>Tue, 14 Sep 2010 21:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72119#M15557</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-14T21:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72120#M15558</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
More elegant than renaming data set would be to solve this issue already on the level of ODS. Not sure if and how this would be done.&lt;BR /&gt;
&lt;BR /&gt;
The code below should do what you asked for:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data data data1 data2 data3;&lt;BR /&gt;
  a=1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let subjectlist=2,3,5;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;  &lt;BR /&gt;
  create view OldDataSets as&lt;BR /&gt;
    select memname as OldName length=32 format=$32.&lt;BR /&gt;
    from dictionary.tables&lt;BR /&gt;
    where libname='WORK' and memname like 'DATA%' and memtype='DATA'&lt;BR /&gt;
      and input(compress(memname,,'kd'),8.) le countw("&amp;amp;subjectlist", ',')&lt;BR /&gt;
      and not missing(input(compress(memname,,'kd'),8.))&lt;BR /&gt;
    order by memname&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
filename temp1 temp;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set OldDataSets end=last;&lt;BR /&gt;
/*  file print;*/&lt;BR /&gt;
  file temp1;&lt;BR /&gt;
&lt;BR /&gt;
  if _n_=1 then&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'proc datasets lib=work nolist nowarn;';&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
  NewName=cats(compress(OldName,,'d'),'n',scan("&amp;amp;subjectlist",_n_,','));&lt;BR /&gt;
  put '  delete ' NewName ';';&lt;BR /&gt;
  put '  change ' OldName ' = ' NewName ';';&lt;BR /&gt;
&lt;BR /&gt;
  if last then&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'quit;';&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%include temp1;&lt;BR /&gt;
&lt;BR /&gt;
filename temp1 clear;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick

Message was edited by: Patrick</description>
      <pubDate>Wed, 15 Sep 2010 12:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72120#M15558</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-09-15T12:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72121#M15559</link>
      <description>Thanks Pat!!</description>
      <pubDate>Wed, 15 Sep 2010 16:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72121#M15559</guid>
      <dc:creator>trekvana</dc:creator>
      <dc:date>2010-09-15T16:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72122#M15560</link>
      <description>You have Patrick's solution, but as an aside to answer one of you questions you have the macro rename.  Here it is rewritten to perform the renames you suggested&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro rename (numb_subj=,ind=);&lt;BR /&gt;
proc datasets;&lt;BR /&gt;
%do i=1 %to &amp;amp;numb_subj;&lt;BR /&gt;
change data&amp;amp;i=datax%left(%scan(&amp;amp;ind,&amp;amp;i));&lt;BR /&gt;
%end;&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend rename;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Where the macro call becomes something like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%rename(numb_subj=5,ind=2 3 5 7 9)&lt;BR /&gt;
[/pre]&lt;BR /&gt;
notice that the DO loop is now %DO and I have changed the statements a bit.&lt;BR /&gt;
HOWEVER there could be overlaps in the names as you had them so I have added an X to the new name.

Message was edited by: ArtC</description>
      <pubDate>Thu, 16 Sep 2010 02:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72122#M15560</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-09-16T02:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: renaming datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72123#M15561</link>
      <description>Or if you know you have no overlaps:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro rename_ds(order);&lt;BR /&gt;
  %local i;&lt;BR /&gt;
  proc datasets nolist;   &lt;BR /&gt;
  %do i=1 %to %sysfunc(countw(&amp;amp;order));&lt;BR /&gt;
  change data&amp;amp;i=____&amp;amp;i ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
  %do i=1 %to %sysfunc(countw(&amp;amp;order));&lt;BR /&gt;
  change ____&amp;amp;i=data%scan(&amp;amp;order,&amp;amp;i) ;&lt;BR /&gt;
  %end;           &lt;BR /&gt;
  quit;&lt;BR /&gt;
%mend rename_ds;&lt;BR /&gt;
&lt;BR /&gt;
%rename_ds(2 3 4 1)&lt;BR /&gt;
[pre]</description>
      <pubDate>Thu, 16 Sep 2010 23:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/renaming-datasets/m-p/72123#M15561</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2010-09-16T23:44:14Z</dc:date>
    </item>
  </channel>
</rss>

