<?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 do you update named range with xlsx engin in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279588#M56358</link>
    <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;Is there any way to update the named range within excel using xlsx in EG?&lt;/P&gt;
&lt;P&gt;I have a client whose EG is running on linux server with no PCfile server installed. I want to export the data into a pre-defined Excel template without using proc export (you can't specify&amp;nbsp;cell range)&amp;nbsp;or ODS&amp;nbsp; as I need to load&amp;nbsp;the data to the proper&amp;nbsp;cell ranges (defined by named range). I&amp;nbsp;need to&amp;nbsp;maintain the excel format&amp;nbsp; while&amp;nbsp; update the data in the named range. Is&amp;nbsp;it possible to&amp;nbsp;achieve that? (Client does not have AMO)&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2016 00:01:24 GMT</pubDate>
    <dc:creator>gyambqt</dc:creator>
    <dc:date>2016-06-23T00:01:24Z</dc:date>
    <item>
      <title>How do you update named range with xlsx engin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279588#M56358</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;Is there any way to update the named range within excel using xlsx in EG?&lt;/P&gt;
&lt;P&gt;I have a client whose EG is running on linux server with no PCfile server installed. I want to export the data into a pre-defined Excel template without using proc export (you can't specify&amp;nbsp;cell range)&amp;nbsp;or ODS&amp;nbsp; as I need to load&amp;nbsp;the data to the proper&amp;nbsp;cell ranges (defined by named range). I&amp;nbsp;need to&amp;nbsp;maintain the excel format&amp;nbsp; while&amp;nbsp; update the data in the named range. Is&amp;nbsp;it possible to&amp;nbsp;achieve that? (Client does not have AMO)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 00:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279588#M56358</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2016-06-23T00:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do you update named range with xlsx engin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279594#M56361</link>
      <description>&lt;P&gt;What version of SAS? (not EG).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the latest version allows it, but not earlier than 9.4.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 01:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279594#M56361</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-23T01:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do you update named range with xlsx engin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279595#M56362</link>
      <description>&lt;P&gt;client is using SAS9.4 M2 with SAS/Access installed and licensed&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 01:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279595#M56362</guid>
      <dc:creator>gyambqt</dc:creator>
      <dc:date>2016-06-23T01:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do you update named range with xlsx engin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279605#M56366</link>
      <description>&lt;P&gt;Named ranges are not supported.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/" target="_blank"&gt;http://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 01:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279605#M56366</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-23T01:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do you update named range with xlsx engin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279845#M56445</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Excel: Replacing data in a named range while maintaing
formatting without SAS Access to PC Files

This post calls R to replace data in the named range.
You may need full SAS for this, especially if you are locked
out of a an operating system.

HAVE

* create excel file with named range "class";
* I am doing this to provide a excel file with a named range;
* you already have the a excel sheet with named range;

* create named range "class";
%utlfkil(d:\xls\class.xlsx); * delete if exists;
libname xls "d:\xls\class.xlsx";
data xls.class;
  set sashelp.class;
;run;quit;

proc contents data=xls._all_;
;run;quit;

libname xls clear;

/*
Libref         XLS
Engine         EXCEL
Physical Name  d:\xls\class.xlsx
User           Admin


                                              DBMS
           Member  Obs, Entries               Member
#  Name    Type     or Indexes   Vars  Label  Type

1  class   DATA         .         5           TABLE
2  class$  DATA         .         5           TABLE


to 40 obs from d:\xls\class.xlsx total obs=19

Rows 1-6 are highlighted in yellow

  Obs    NAME       SEX    AGE    HEIGHT    WEIGHT

    1    Alfred      M      14     69.0      112.5
    2    Alice       F      13     56.5       84.0
    3    Barbara     F      13     65.3       98.0
    4    Carol       F      14     62.8      102.5
    5    Henry       M      14     63.5      102.5
....
*/

WANT (with rows 1-6 highlighted in yellow - retained)
(sorted by descending name)

        NAME SEX AGE HEIGHT WEIGHT
  1   William  M  15   66.5  112.0
  2   Thomas   M  11   57.5   85.0
  3   Ronald   M  15   67.0  133.0
  4   Robert   M  12   64.8  128.0
  5   Philip   M  16   72.0  150.0

SOLUTION

* Create some replacement data;

* dataset to overwrite named region data keeping your customizations;
proc sort data=sashelp.class out="d:/sd1/newclass.sas7bdat";
by descending name;
run;quit;

* overwite data in named range class;
%utl_submit_r64(%nrbquote(
   library(XLConnect);
   library(haven);
   newclass&amp;lt;-read_sas("d:/sd1/newclass.sas7bdat");
   wb &amp;lt;- loadWorkbook("d:/xls/class.xlsx");
   /* set Style says to retain formatting */
   setStyleAction(wb,XLC$"STYLE_ACTION.NONE");
   writeNamedRegion(wb,newclass,name="class");
   saveWorkbook(wb);
  ));


%macro utl_submit_R64(pgmx)/des="Semi colon separated set of R commands";
  * write the program to a temporary file;
  filename r_pgm temp lrecl=32766 recfm=v;
  data _null_;
    file r_pgm;
    pgm=compbl("&amp;amp;pgmx");
    put pgm;
    putlog pgm;
  run;
  %let __loc=%sysfunc(pathname(r_pgm));
  * pipe file through R;
  filename rut pipe "c:\Progra~1\R\R-3.2.4\bin\x64\R --quiet --no-save &amp;lt; &amp;amp;__loc";
  data _null_;
    file print;
    infile rut;
    input;
    put _infile_;
    putlog _infile_;
  run;
  filename rut clear;
  filename r_pgm clear;
%mend utl_submit_r64;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/279845#M56445</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-06-23T20:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do you update named range with xlsx engin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/280036#M56526</link>
      <description>You can try the macro here. Not sure if it works on Unix. &lt;A href="http://www.sascommunity.org/wiki/A_Poor/Rich_SAS_Users_Proc_Export" target="_blank"&gt;http://www.sascommunity.org/wiki/A_Poor/Rich_SAS_Users_Proc_Export&lt;/A&gt;</description>
      <pubDate>Fri, 24 Jun 2016 17:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-you-update-named-range-with-xlsx-engin/m-p/280036#M56526</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-24T17:36:24Z</dc:date>
    </item>
  </channel>
</rss>

