<?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 perform a same operation all sheets of a excel file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354442#M82927</link>
    <description>&lt;P&gt;Please find my data pic and excel sheet, i&amp;nbsp;had read my data as work.jan&amp;nbsp;, work.feb, ..... so on. &amp;nbsp;suppose&amp;nbsp;i want to add new column which has diffrence of column H and G in each excel sheet (12 sheets, please see below ), Further&amp;nbsp;i want write that data intoto new data variable like work.p_jan, work._feb....so on. Thanku&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8619i3BD2D75E16BEFC3D/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture_lat.PNG" title="Capture_lat.PNG" /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Apr 2017 12:34:36 GMT</pubDate>
    <dc:creator>ervinodsingh</dc:creator>
    <dc:date>2017-04-28T12:34:36Z</dc:date>
    <item>
      <title>How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354391#M82908</link>
      <description>&lt;P&gt;Hi i have read data from all&amp;nbsp;sheets of an excel file. But i want to perform the same operation on the data of every sheet of excel file and want to save the results in a different&amp;nbsp;dataset name. My code is given below, i have used "ods trace....." and dataset to list datasets available&amp;nbsp;in IN library. I want to read each data from IN library and perform the same operation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname in xlsx '/folders/myfolders/q_data _final1.xlsx';
proc copy inlib=in outlib=work;
run;     

ods trace on;
proc datasets library=IN memtype=data;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 10:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354391#M82908</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-04-28T10:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354398#M82911</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="WORK"));
  call execute('data work.p_'||strip(memname)||'; set work.'||strip(memname)||'; id=1; run;');
run;&lt;/PRE&gt;
&lt;P&gt;What the above code does is for every dataset in WORK, generate a datastep which looks like:&lt;/P&gt;
&lt;P&gt;data work.p_&amp;lt;name of dataset&amp;gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set work.&amp;lt;name of dataste&amp;gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; id=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the p_ in the first row, that is the new dataset created from the old, and id variable is added. &amp;nbsp;You just need to change id=1; to be your logic (of which you have not provided test data in the form of a datastep, what the output should look like, or what your logic is - so can't help there).&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 10:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354398#M82911</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-28T10:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354406#M82913</link>
      <description>&lt;P&gt;Your trick worked for me but how I will introduce the logic. Suppose I want to subtract a var1 from var2 and write that data to a new file. I want to do this for all datasets belonging to different sheets. &amp;nbsp;Thankyou&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 10:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354406#M82913</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-04-28T10:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354411#M82916</link>
      <description>&lt;P&gt;You need to get the list of dataset names to drive generating the code for each.&lt;/P&gt;
&lt;P&gt;You could use PROC CONTENTS to get the names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname in xlsx '/folders/myfolders/q_data _final1.xlsx';
proc contents data=in._all_ noprint out=contents; 
run;
data dslist ;
  set contents;
  by memname ;
  if first.memname ;
  keep libname memname ;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could keep the list in that data step or generate a macro variable with a space delimited list of member names or a series of macro variables that each have one name.&lt;/P&gt;
&lt;P&gt;There are lots of ways to generate code once you have the list. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could make a macro that take the member name as input&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro process1(memname);
   .... &amp;amp;memname ....
%mend process1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then generate a series of calls to the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%process1(sheet1);
%process1(sheet2);
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could code the macro to take a series of names,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro process_list(memlist);
%local i memname ;
%do i=1 %to %sysfunc(countw(&amp;amp;memlist));
  %let memname=%scan(&amp;amp;memlist,&amp;amp;i);
   .... &amp;amp;memname ....
%end;
%mend process_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or take a libref and generate the series of names for itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro process_libt(libname);
proc contents data=&amp;amp;libname.._all_ noprint out=contents; run;
...
%mend process_lib;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a data step to generate CALL EXECUTE() statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set dslist;
  call execute(cats('%nrstr(%process1)(',memname,')');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a data step to write SAS code to a file and then %INCLUDE the generated code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set dslist;
  file code;
  put '%process1(' memname ')' ;
run;
%include code /source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use PROC SQL to select code into a macro variable and then expand the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cats('%process1(',memname,')')
    into :calls separated by ';'
    from contents
  ;
quit;
&amp;amp;calls;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 10:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354411#M82916</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-28T10:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354422#M82923</link>
      <description>&lt;P&gt;You may want to refer to my post:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;You just need to change id=1; to be your logic (of which you have not provided test data in the form of a datastep, what the output should look like, or what your logic is - so can't help there)."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In the data _null_; change the id=1 bit to what your logic is. &amp;nbsp;Since you haven't provided an test data, required output, or logic, I can't tell you exactly how that will look.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 11:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354422#M82923</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-28T11:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354442#M82927</link>
      <description>&lt;P&gt;Please find my data pic and excel sheet, i&amp;nbsp;had read my data as work.jan&amp;nbsp;, work.feb, ..... so on. &amp;nbsp;suppose&amp;nbsp;i want to add new column which has diffrence of column H and G in each excel sheet (12 sheets, please see below ), Further&amp;nbsp;i want write that data intoto new data variable like work.p_jan, work._feb....so on. Thanku&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8619i3BD2D75E16BEFC3D/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture_lat.PNG" title="Capture_lat.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 12:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354442#M82927</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-04-28T12:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354447#M82929</link>
      <description>&lt;P&gt;This is not of use to me, I cannot code against a picture, and downloading files from the net is a no-no. &amp;nbsp;Look at other posts here for how to post data, or refer to:&lt;/P&gt;
&lt;P&gt;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to have a new column with H-G then update the code I provided to (this assumes the columns read in are actually named h and g) - I have laid out the code so it is clearer for you:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="WORK"));
  call execute('data work.p_'||strip(memname)||'; &lt;BR /&gt;                  set work.'||strip(memname)||'; &lt;BR /&gt;                  result=h-g; &lt;BR /&gt;                run;');
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 12:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/354447#M82929</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-28T12:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/355184#M83195</link>
      <description>&lt;P&gt;Thanks, RW9 your trick worked well for me. I just replaced 'h' and 'g' with the column name of my data.&lt;img id="manhappy" class="emoticon emoticon-manhappy" src="https://communities.sas.com/i/smilies/16x16_man-happy.png" alt="Man Happy" title="Man Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 10:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/355184#M83195</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-02T10:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/355860#M83371</link>
      <description>&lt;P&gt;Sorry for disturbing you again, I want to know that i have got my results in work.p_jan, work.p_feb...... by the code you provided. Now i want to put "result" column of all these datasets generated into one data. i have tried to modify your code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.vtable (where=(libname="IN"));
  call execute('data work.results;  /* vtable have library names and corresponding memenames */ 
 		  keep $ '||strip(memname)||'
                  set work.p_'||strip(memname)||' ; 
                  '||strip(memname)||'= result
                  
                run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to put results to work.results which is supposed to have 12 columns each for a month from the "work.p_ month" datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 07:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/355860#M83371</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-04T07:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a same operation all sheets of a excel file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/355882#M83373</link>
      <description>&lt;P&gt;Post a new topic. &amp;nbsp;Start by giving &lt;STRONG&gt;test in the form of a datastep&lt;/STRONG&gt; and what you want the output to look like. &amp;nbsp;Your question has now changed. &amp;nbsp;Why are you wanting to create seprate datasets and then combine them back again, thats just a waste of disk space. &amp;nbsp;Forumlate a new topic with exact inputs and outputs to get a good answer.&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 08:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-a-same-operation-all-sheets-of-a-excel-file/m-p/355882#M83373</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-04T08:31:18Z</dc:date>
    </item>
  </channel>
</rss>

