<?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 Using SAS with Excel - Open workbook, copy and past as values, save and close in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405942#M279197</link>
    <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a unique problem and need some help. I need to create a SAS script that opens an excel workbook, selects everything, copies it, and then pastes it all as values, saves it, then closes it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fairly straight forward although I have limited experience working with Excel from SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wont get into the details too much, but we use this excel file&amp;nbsp;to load another application, and some of my values (labels mostly)&amp;nbsp;are coming out in&amp;nbsp;Excel with&amp;nbsp;" " quotes around them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The simplest solution is to have&amp;nbsp;a short script at the end that just copy and pastes the values into the same workbook.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a starting point, but does not do what I want. The code below opens a workbook, selects a specific tab of a work sheet, saves then closes. I&amp;nbsp;need it to copy and paste values then save and close. Its a starting point anyway, but Im out my depth here... Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; Selecting_Excel_Sheet (Analyst);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;length script filevar $&lt;STRONG&gt;256&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;script = catx('\',pathname('WORK'),'PasteIt.vbs');&lt;/P&gt;&lt;P&gt;filevar = script;&lt;/P&gt;&lt;P&gt;script="'"||'cscript "'||trim(script)||'"'||"'";&lt;/P&gt;&lt;P&gt;call symput('script',script);&lt;/P&gt;&lt;P&gt;file dummy1 filevar=filevar recfm=v lrecl=&lt;STRONG&gt;512&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;put 'Dim objExcel';&lt;/P&gt;&lt;P&gt;put 'Dim OldBook';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;put 'set objExcel = CreateObject("Excel.Application")';&lt;/P&gt;&lt;P&gt;script=catt('Set OldBook=objExcel.Workbooks.Open("',"&amp;amp;FilePath.\&amp;amp;Analyst. &amp;amp;Year.Q&amp;amp;Quarter. FFA.xlsx",'")');&lt;/P&gt;&lt;P&gt;put script;&lt;/P&gt;&lt;P&gt;put 'OldBook.Sheets("Income").Select';&lt;/P&gt;&lt;P&gt;put 'OldBook.Sheets("Investment").Select';&lt;/P&gt;&lt;P&gt;put 'objExcel.DisplayAlerts = False';&lt;/P&gt;&lt;P&gt;put 'OldBook.Save';&lt;/P&gt;&lt;P&gt;put 'OldBook.Close';&lt;/P&gt;&lt;P&gt;put 'objExcel.DisplayAlerts = True';&lt;/P&gt;&lt;P&gt;put 'objExcel.Quit';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call system(&amp;amp;script.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 13:20:25 GMT</pubDate>
    <dc:creator>soontobeexpert</dc:creator>
    <dc:date>2017-10-20T13:20:25Z</dc:date>
    <item>
      <title>Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405942#M279197</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a unique problem and need some help. I need to create a SAS script that opens an excel workbook, selects everything, copies it, and then pastes it all as values, saves it, then closes it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fairly straight forward although I have limited experience working with Excel from SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wont get into the details too much, but we use this excel file&amp;nbsp;to load another application, and some of my values (labels mostly)&amp;nbsp;are coming out in&amp;nbsp;Excel with&amp;nbsp;" " quotes around them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The simplest solution is to have&amp;nbsp;a short script at the end that just copy and pastes the values into the same workbook.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a starting point, but does not do what I want. The code below opens a workbook, selects a specific tab of a work sheet, saves then closes. I&amp;nbsp;need it to copy and paste values then save and close. Its a starting point anyway, but Im out my depth here... Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; Selecting_Excel_Sheet (Analyst);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;length script filevar $&lt;STRONG&gt;256&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;script = catx('\',pathname('WORK'),'PasteIt.vbs');&lt;/P&gt;&lt;P&gt;filevar = script;&lt;/P&gt;&lt;P&gt;script="'"||'cscript "'||trim(script)||'"'||"'";&lt;/P&gt;&lt;P&gt;call symput('script',script);&lt;/P&gt;&lt;P&gt;file dummy1 filevar=filevar recfm=v lrecl=&lt;STRONG&gt;512&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;put 'Dim objExcel';&lt;/P&gt;&lt;P&gt;put 'Dim OldBook';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;put 'set objExcel = CreateObject("Excel.Application")';&lt;/P&gt;&lt;P&gt;script=catt('Set OldBook=objExcel.Workbooks.Open("',"&amp;amp;FilePath.\&amp;amp;Analyst. &amp;amp;Year.Q&amp;amp;Quarter. FFA.xlsx",'")');&lt;/P&gt;&lt;P&gt;put script;&lt;/P&gt;&lt;P&gt;put 'OldBook.Sheets("Income").Select';&lt;/P&gt;&lt;P&gt;put 'OldBook.Sheets("Investment").Select';&lt;/P&gt;&lt;P&gt;put 'objExcel.DisplayAlerts = False';&lt;/P&gt;&lt;P&gt;put 'OldBook.Save';&lt;/P&gt;&lt;P&gt;put 'OldBook.Close';&lt;/P&gt;&lt;P&gt;put 'objExcel.DisplayAlerts = True';&lt;/P&gt;&lt;P&gt;put 'objExcel.Quit';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call system(&amp;amp;script.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 13:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405942#M279197</guid>
      <dc:creator>soontobeexpert</dc:creator>
      <dc:date>2017-10-20T13:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405948#M279198</link>
      <description>&lt;P&gt;SAS enables read excel worksheets into sas dataset (importing the data) or&lt;/P&gt;
&lt;P&gt;write it into excel sheets (exporting).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not clear what do you mean by copy/paste the values ?&lt;/P&gt;
&lt;P&gt;What kind of output should it be? A sas dataset or an excel worksheet ?&lt;/P&gt;
&lt;P&gt;If the output is an execl sheet - how should output differ from input?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Importing data from excel - the column should be either a charcter type or numeric type.&lt;/P&gt;
&lt;P&gt;Sas examines the values of a column, enables one or more rows to hold the label, then&lt;/P&gt;
&lt;P&gt;according the other rows deine its type.&lt;/P&gt;
&lt;P&gt;Dou you need the labels in the output? or you want to skip over?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Beyond, your macro misses the %MEND; line to close, and I did not check your macro details.&lt;/P&gt;
&lt;P&gt;Why do you need a macro? What arguments you want to supply?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 13:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405948#M279198</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-20T13:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405956#M279199</link>
      <description>&lt;P&gt;Hey Shmuel, thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS can do a lot more than just import and export from and into Excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to write some code in SAS&amp;nbsp;that&amp;nbsp;opens an Excel workbook of my choosing, selects the entire range (sheet), copies the range, pastes the range as values (thus removing and " " quotes that exist&amp;nbsp;in my data), saves the workbook&amp;nbsp;and then closes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could liken what I am trying to do to an import then immediate &amp;nbsp;re-export, but the data is already created... so importing a workbook, then re-exporting&amp;nbsp;it wouldn't change anything; my data would still contain the " " values. Staying in Excel, and copying and pasting as values gets around this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I need to maintain all labels, but the "&amp;nbsp; " are not solely in the labels, hence why I'm trying to avoid any hardcoded label name approaches.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 14:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405956#M279199</guid>
      <dc:creator>soontobeexpert</dc:creator>
      <dc:date>2017-10-20T14:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405982#M279200</link>
      <description>&lt;P&gt;I think this is a right tool for the right job situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do this in SAS, most likely using DDE though and that's outdated so I don't recommend that anymore...but it's definitely possible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, I suspect a VB macro is a better solution. I would also consider fixing it in a different way if possible. How are you creating the Excel file in the first place, how is the data getting there with quotes. I'd probably fix that process instead.&amp;nbsp; Assuming your response is, that's not possible/out of my control here's one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://analytics.ncsu.edu/sesug/2013/HOW-09.pdf" target="_blank"&gt;http://analytics.ncsu.edu/sesug/2013/HOW-09.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, search on Lexjansen.com for this and you'll find examples. You'll need to make sure you have X commands enabled, for example this won't work in SAS Studio or EG.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 15:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405982#M279200</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T15:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405987#M279201</link>
      <description>&lt;P&gt;You can remove the " " by several ways:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) new_var = compress(old_var,'"'); /* will remove all double auotes */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) new_var = substr(old_var,2,length(old_var) - 1); /* will keep mid quotes */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 15:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/405987#M279201</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-20T15:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/406001#M279202</link>
      <description>&lt;P&gt;Hey again, all valid answers I and I will definitely explore them! Thanks for all the input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example in my first question&amp;nbsp;was not for this process; something entirely different. I just thought it would save some time in getting across what I was trying to achieve. I don't know how to write DDE mark-up to do what I am trying to do, was merely posting a similar example.&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 15:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/406001#M279202</guid>
      <dc:creator>soontobeexpert</dc:creator>
      <dc:date>2017-10-20T15:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/406039#M279203</link>
      <description>&lt;P&gt;Trying to attack this problem I realized why I&amp;nbsp;remember&amp;nbsp;why I thought&amp;nbsp;ODS might be best approach. Some of the labels I have begin with numbers; something SAS doesn't like ex. 17Q1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just some logic for the approach...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 17:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/406039#M279203</guid>
      <dc:creator>soontobeexpert</dc:creator>
      <dc:date>2017-10-20T17:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using SAS with Excel - Open workbook, copy and past as values, save and close</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/406045#M279204</link>
      <description>&lt;P&gt;OPTION VALIDVARNAME=ANY allows SAS to have names that start with numbers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/141437"&gt;@soontobeexpert&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Trying to attack this problem I realized why I&amp;nbsp;remember&amp;nbsp;why I thought&amp;nbsp;ODS might be best approach. Some of the labels I have begin with numbers; something SAS doesn't like ex. 17Q1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just some logic for the approach...&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ODS doesn't fit into this process that you've mentioned. If you created a file via ODS then its highly likely the issue can be fixed before you export the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 17:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-SAS-with-Excel-Open-workbook-copy-and-past-as-values-save/m-p/406045#M279204</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T17:39:30Z</dc:date>
    </item>
  </channel>
</rss>

