<?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: Macro variable used in a cell range definition using DDE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61422#M13348</link>
    <description>Thanks a lot, Cynthia! Everything works fine now! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Sat, 07 Aug 2010 03:25:42 GMT</pubDate>
    <dc:creator>keyreal</dc:creator>
    <dc:date>2010-08-07T03:25:42Z</dc:date>
    <item>
      <title>Macro variable used in a cell range definition using DDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61420#M13346</link>
      <description>Hello guys! I am trying to do the following: &lt;BR /&gt;
1) Export a SAS data set to an Excel output file;&lt;BR /&gt;
2) Open the same Excel output file from within SAS using DDE;&lt;BR /&gt;
3) Select all data populated cells;&lt;BR /&gt;
&lt;BR /&gt;
My problem comes when I try to use a macro variable &amp;amp;r (which resolves to the total number of rows including column headers) in defining the cell range selection. When I run the program I get an error which is shown below from my SAS log.&lt;BR /&gt;
Any ideas how to fix this problem will be greatly appreciated! Thanks in advance!&lt;BR /&gt;
***************************************************************************************&lt;BR /&gt;
61   options symbolgen;&lt;BR /&gt;
62   %let today = %qsysfunc(today(),date9.);&lt;BR /&gt;
63   %let file = "C:\SAS Tests\testexcel as of &amp;amp;today..xls";&lt;BR /&gt;
SYMBOLGEN:  Macro variable TODAY resolves to 06AUG2010&lt;BR /&gt;
64   data test;&lt;BR /&gt;
65   input Name $ Age Country $;&lt;BR /&gt;
66   cards;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The data set WORK.TEST has 4 observations and 3 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
71   ;&lt;BR /&gt;
72   run;&lt;BR /&gt;
73   proc export data = test outfile=&amp;amp;file replace; sheet = 'people'; run;&lt;BR /&gt;
SYMBOLGEN:  Macro variable FILE resolves to "C:\SAS Tests\testexcel as of 06AUG2010.xls"&lt;BR /&gt;
&lt;BR /&gt;
NOTE: File "C:\SAS Tests\testexcel as of 06AUG2010.xls" will be created if the export process&lt;BR /&gt;
      succeeds.&lt;BR /&gt;
NOTE: "people" range/sheet was successfully created.&lt;BR /&gt;
NOTE: PROCEDURE EXPORT used (Total process time):&lt;BR /&gt;
      real time           0.85 seconds&lt;BR /&gt;
      cpu time            0.29 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
74   options noxwait noxsync;&lt;BR /&gt;
75   data _null_;&lt;BR /&gt;
76   rc=system('start excel');&lt;BR /&gt;
77   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.03 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
78   data _null_;&lt;BR /&gt;
79   x=sleep(8);&lt;BR /&gt;
80   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           8.23 seconds&lt;BR /&gt;
      cpu time            0.23 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
81   filename cmds dde 'excel|system';&lt;BR /&gt;
82   data _null_;&lt;BR /&gt;
83   file cmds;&lt;BR /&gt;
SYMBOLGEN:  Macro variable FILE resolves to "C:\SAS Tests\testexcel as of 06AUG2010.xls"&lt;BR /&gt;
84   put "[open("&amp;amp;file")]";&lt;BR /&gt;
85   x=sleep(5);&lt;BR /&gt;
86   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: The file CMDS is:&lt;BR /&gt;
      DDE Session,&lt;BR /&gt;
      SESSION=excel|system,RECFM=V,LRECL=256&lt;BR /&gt;
&lt;BR /&gt;
NOTE: 1 record was written to the file CMDS.&lt;BR /&gt;
      The minimum record length was 52.&lt;BR /&gt;
      The maximum record length was 52.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           5.60 seconds&lt;BR /&gt;
      cpu time            0.17 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
87   data _null_;&lt;BR /&gt;
88   set test NOBS=rows;&lt;BR /&gt;
89   call symput ('rows',rows);&lt;BR /&gt;
90   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Numeric values have been converted to character values at the places given by:&lt;BR /&gt;
      (Line):(Column).&lt;BR /&gt;
      89:21&lt;BR /&gt;
NOTE: There were 4 observations read from the data set WORK.TEST.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SYMBOLGEN:  Macro variable ROWS resolves to            4&lt;BR /&gt;
91   %let r = %eval(&amp;amp;rows + 1);&lt;BR /&gt;
92   data _null_;&lt;BR /&gt;
93   file cmds;&lt;BR /&gt;
94   put '[workbook.activate("people")]';&lt;BR /&gt;
95   put "[select("R1C1:R&amp;amp;rC3")]";&lt;BR /&gt;
         ----------&lt;BR /&gt;
         49&lt;BR /&gt;
WARNING: Apparent symbolic reference RC3 not resolved.&lt;BR /&gt;
NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS&lt;BR /&gt;
             release.  Inserting white space between a quoted string and the succeeding&lt;BR /&gt;
             identifier is recommended.&lt;BR /&gt;
&lt;BR /&gt;
96   run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Variable R1C1 is uninitialized.&lt;BR /&gt;
NOTE: Variable R is uninitialized.&lt;BR /&gt;
NOTE: Variable rC3 is uninitialized.&lt;BR /&gt;
NOTE: The file CMDS is:&lt;BR /&gt;
      DDE Session,&lt;BR /&gt;
      SESSION=excel|system,RECFM=V,LRECL=256&lt;BR /&gt;
&lt;BR /&gt;
ERROR: DDE session not ready.&lt;BR /&gt;
FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.&lt;BR /&gt;
       Aborted during the EXECUTION phase.&lt;BR /&gt;
NOTE: 1 record was written to the file CMDS.&lt;BR /&gt;
      The minimum record length was 29.&lt;BR /&gt;
      The maximum record length was 29.&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.04 seconds&lt;BR /&gt;
      cpu time            0.01 seconds</description>
      <pubDate>Sat, 07 Aug 2010 00:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61420#M13346</guid>
      <dc:creator>keyreal</dc:creator>
      <dc:date>2010-08-07T00:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable used in a cell range definition using DDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61421#M13347</link>
      <description>Hi:&lt;BR /&gt;
  The error message is quite clear:&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
WARNING: Apparent symbolic reference RC3 not resolved.&lt;BR /&gt;
&lt;/B&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Because when the word scanner encountered&lt;BR /&gt;
&lt;B&gt;[pre]&lt;BR /&gt;
R&amp;amp;rC3&lt;BR /&gt;
&lt;/B&gt;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The word scanner interpreted the macro variable as: &amp;amp;RC3 and so it went to the GLOBAL symbol table and did not find &amp;amp;RC3 so the macro word scanner gave you a warning and the unresolved macro variable reference went forward to the code compiler. You need to delimit the &amp;amp;R, so that the constant C3 is not considered part of the macro variable name. A single period is used as a delimiter to tell the macro word scanner when to stopd reading characters and to start resolving. So the correct reference should have been:&lt;BR /&gt;
&lt;B&gt;[pre]&lt;BR /&gt;
R&amp;amp;r.C3&lt;BR /&gt;
&lt;/B&gt;[/pre]&lt;BR /&gt;
                                                   &lt;BR /&gt;
The way the word scanner works is that the &amp;amp; is a macro trigger and everything between the &amp;amp; and the . is considered to be the macro variable reference to be looked up. Essentially, the single . disappears from the macro variable reference upon resolution. If you NEEDED to have a dot in a name, such as in a two level lib and dataset name, then you would use 2 periods, such as shown below:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let lib=sashelp;&lt;BR /&gt;
%let dsn = class;&lt;BR /&gt;
proc print data=&amp;amp;lib..&amp;amp;dsn;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
              &lt;BR /&gt;
Consider this program, which duplicates your error message and shows the correct way to concatenate the 'C3' onto the &amp;amp;R value (program and log output both shown). Also, I believe that the correct command that you want to &lt;BR /&gt;
generate is: &lt;B&gt;[select("R1C1:R20C3")]&lt;/B&gt; with quotes around the row/column reference. Note that to accomplish that set of quotes -and- to have the macro variable resolved, you need to surround the row/column reference with doubled quotes, as in: &lt;B&gt;putlog "[select(""R1C1:R&amp;amp;r.C3"")]";&lt;/B&gt;&lt;BR /&gt;
                    &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
632    data _null_;&lt;BR /&gt;
633    set sashelp.class NOBS=rows;&lt;BR /&gt;
634    call symput ('rows',rows);&lt;BR /&gt;
635    run;&lt;BR /&gt;
                                  &lt;BR /&gt;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;
      634:23&lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
                        &lt;BR /&gt;
636    %put rows= &amp;amp;rows;&lt;BR /&gt;
rows=           19&lt;BR /&gt;
637&lt;BR /&gt;
638    %let r = %eval(&amp;amp;rows + 1);&lt;BR /&gt;
639    %put r= &amp;amp;r;&lt;BR /&gt;
r= 20&lt;BR /&gt;
640    %put *****  Note the use of the . (period) to indicate the end of the macro variable reference;&lt;BR /&gt;
*****  Note the use of the . (period) to indicate the end of the macro variable reference&lt;BR /&gt;
641    %put *****  Resolved macro variable reference: r1c1:r&amp;amp;r.c3 ;&lt;BR /&gt;
*****  Resolved macro variable reference: r1c1:r20c3&lt;BR /&gt;
642    %put ***** INCORRECT: r1c1:r&amp;amp;rc3;&lt;BR /&gt;
WARNING: Apparent symbolic reference RC3 not resolved.&lt;BR /&gt;
***** INCORRECT: r1c1:r&amp;amp;rc3&lt;BR /&gt;
643&lt;BR /&gt;
644    data _null_;&lt;BR /&gt;
645    putlog '***** Test resolution of Macro variable *****';&lt;BR /&gt;
646    putlog '***** Note the extra double quotes around the values in the SELECT command';&lt;BR /&gt;
647    putlog '[workbook.activate("people")]';&lt;BR /&gt;
648    putlog "[select(""R1C1:R&amp;amp;r.C3"")]";&lt;BR /&gt;
649    run;&lt;BR /&gt;
                  &lt;BR /&gt;
***** Test resolution of Macro variable *****&lt;BR /&gt;
***** Note the extra double quotes around the values in the SELECT command&lt;BR /&gt;
[workbook.activate("people")]&lt;BR /&gt;
[select("R1C1:R20C3")]&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sat, 07 Aug 2010 02:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61421#M13347</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-07T02:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable used in a cell range definition using DDE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61422#M13348</link>
      <description>Thanks a lot, Cynthia! Everything works fine now! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sat, 07 Aug 2010 03:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-used-in-a-cell-range-definition-using-DDE/m-p/61422#M13348</guid>
      <dc:creator>keyreal</dc:creator>
      <dc:date>2010-08-07T03:25:42Z</dc:date>
    </item>
  </channel>
</rss>

