<?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 how to alter multiple datasets in same library and add a new column into them. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-alter-multiple-datasets-in-same-library-and-add-a-new/m-p/937197#M45069</link>
    <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;Thank you in advance for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a library in SAS and i have 50 datasets in it. below is an example&lt;/P&gt;&lt;P&gt;LIBNAME XXXXX SASSPDS&lt;BR /&gt;IP=YES LIBGEN=YES&lt;BR /&gt;HOST='Local' Serv='1111'&lt;BR /&gt;SCHEMA="xx0000" USER="xxx11spds"&lt;BR /&gt;PASSWORD="xxxxxx";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to add a new variable in all the 50 datasets.&lt;/P&gt;&lt;P&gt;1)employee.sas&lt;/P&gt;&lt;P&gt;2)batch.sas&lt;/P&gt;&lt;P&gt;3)task.sas&lt;/P&gt;&lt;P&gt;4)edge.sas&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;50)kohnge.sas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here i have written for one dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;ALTER TABLE XXXXX.employee Add salary CHAR (10) Label='employeesalary';&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it will take lot of time to write for all 50 datasets like above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me in this scenario to write same code to update all the 50 datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Br,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2024 08:07:07 GMT</pubDate>
    <dc:creator>Pandu</dc:creator>
    <dc:date>2024-07-26T08:07:07Z</dc:date>
    <item>
      <title>how to alter multiple datasets in same library and add a new column into them.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-alter-multiple-datasets-in-same-library-and-add-a-new/m-p/937197#M45069</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;Thank you in advance for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a library in SAS and i have 50 datasets in it. below is an example&lt;/P&gt;&lt;P&gt;LIBNAME XXXXX SASSPDS&lt;BR /&gt;IP=YES LIBGEN=YES&lt;BR /&gt;HOST='Local' Serv='1111'&lt;BR /&gt;SCHEMA="xx0000" USER="xxx11spds"&lt;BR /&gt;PASSWORD="xxxxxx";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to add a new variable in all the 50 datasets.&lt;/P&gt;&lt;P&gt;1)employee.sas&lt;/P&gt;&lt;P&gt;2)batch.sas&lt;/P&gt;&lt;P&gt;3)task.sas&lt;/P&gt;&lt;P&gt;4)edge.sas&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;50)kohnge.sas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here i have written for one dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;ALTER TABLE XXXXX.employee Add salary CHAR (10) Label='employeesalary';&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it will take lot of time to write for all 50 datasets like above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me in this scenario to write same code to update all the 50 datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Br,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 08:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-alter-multiple-datasets-in-same-library-and-add-a-new/m-p/937197#M45069</guid>
      <dc:creator>Pandu</dc:creator>
      <dc:date>2024-07-26T08:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to alter multiple datasets in same library and add a new column into them.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-alter-multiple-datasets-in-same-library-and-add-a-new/m-p/937243#M45074</link>
      <description>&lt;P&gt;A macro program can do this pretty easily, assuming you want to add the same column to all the datasets. Here is some working starter code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* This is just setting up some datasets to use for testing */
/* Make sure the WORK library is empty at the start */
proc datasets library=work kill nolist nodetails;
run; quit;

/* Copy in some datasets to work with */
proc copy in=sashelp out=work;
select class cars fish iris;
run;

/*****************************************************
&amp;nbsp;The work starts here&amp;nbsp;
*****************************************************/

/* Create a macro program to perform the bulk table alterations */
%macro AddColumn(libref,Name,Label,Length);
/* Get all of the table names into a series of macro variables */
proc sql noprint;
select memname&amp;nbsp;
into :table1-
from dictionary.tables
where libname ="%upcase(%superq(libref))";
;
quit;
%let numTables=&amp;amp;sqlobs;
/* Set up the alter table requirements */
%if &amp;amp;length = %then&amp;nbsp;
%let newCol=add &amp;amp;name num label="%superq(label)";
%else
%let newCol=add &amp;amp;name char(&amp;amp;length) label="%superq(label)";
/* add the column to all the tables */
proc sql;
%do i=1 %to &amp;amp;numTables;
ALTER TABLE &amp;amp;libref..&amp;amp;&amp;amp;table&amp;amp;i&amp;nbsp;
&amp;amp;newcol;
%end;
quit;
%mend;

/* Initial Table structure report */
title "Table Structure Before Modification";
ods&amp;nbsp; select Position;
proc contents data=work._all_ varnum;
run;
/* Use the macro to add a 10 character column named myNewCharCol */
%AddColumn(work,myNewCharCol,New Character Column,10)

/* Post Modification Table structure report */
title "Table Structure After myNewCharCol Add";
ods  select Position;
proc contents data=work._all_ varnum;
run;

/* Use the macro to add a numeric column named myNewNumeric */
%AddColumn(work,myNewNumeric,New Numeric Column)

/* Post Modification Table structure report */
title "Table Structure After myNewNumeric Add";
ods  select Position;
proc contents data=work._all_ varnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 13:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-alter-multiple-datasets-in-same-library-and-add-a-new/m-p/937243#M45074</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-07-26T13:00:15Z</dc:date>
    </item>
  </channel>
</rss>

