<?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 Apostrophe in a variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744926#M233442</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have through a series of macros imported data from forms sent to me in Excel, where I have each answer in their own separate table named "DDDXXX" (as in DDD004, DDD342 etc.). Some of the questions have lengthy answers, and in their separate tables, the answers are still in their original length.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Almost all variables have a name with a space between two words, and some also have an apostrophe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to sum these tables into one, SAS seem to guess what the length of each variable should be, and will change the length. This results in a lot of answers being cut short.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the Variable names with a space bar I have managed to work out to use the following input to keep the full length of the answers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data NAME_OF_NEW_TABLE  ;
length 'Question-ID'n $35. 'Action done'n $40. 'Explain action'n $400.;
set DDD:;
format 'Question-ID'n $35. 'Action done'n $40. 'Explain action'n $400.;
keep 'Question-ID'n 'Action done'n 'Explain action'n;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I have a variable with a apostrophe in the name, I have not managed to figure out how to work around it. Since 'Action's result'n will not read the full variable name, because of the extra apostrophe.&lt;/P&gt;&lt;P&gt;If I first compile one table with all separate tables, and rename the varibles, and then try and change the length of the variable, the answers seem to have been cut short in the first step. Changing the length again does not bring the rest of the answer back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it possible to use my above code to get the same effect, but for a variable with an apostrophe?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Gustav&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jun 2021 13:11:07 GMT</pubDate>
    <dc:creator>GustavSandberg</dc:creator>
    <dc:date>2021-06-01T13:11:07Z</dc:date>
    <item>
      <title>Apostrophe in a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744926#M233442</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have through a series of macros imported data from forms sent to me in Excel, where I have each answer in their own separate table named "DDDXXX" (as in DDD004, DDD342 etc.). Some of the questions have lengthy answers, and in their separate tables, the answers are still in their original length.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Almost all variables have a name with a space between two words, and some also have an apostrophe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to sum these tables into one, SAS seem to guess what the length of each variable should be, and will change the length. This results in a lot of answers being cut short.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the Variable names with a space bar I have managed to work out to use the following input to keep the full length of the answers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data NAME_OF_NEW_TABLE  ;
length 'Question-ID'n $35. 'Action done'n $40. 'Explain action'n $400.;
set DDD:;
format 'Question-ID'n $35. 'Action done'n $40. 'Explain action'n $400.;
keep 'Question-ID'n 'Action done'n 'Explain action'n;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when I have a variable with a apostrophe in the name, I have not managed to figure out how to work around it. Since 'Action's result'n will not read the full variable name, because of the extra apostrophe.&lt;/P&gt;&lt;P&gt;If I first compile one table with all separate tables, and rename the varibles, and then try and change the length of the variable, the answers seem to have been cut short in the first step. Changing the length again does not bring the rest of the answer back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it possible to use my above code to get the same effect, but for a variable with an apostrophe?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Gustav&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 13:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744926#M233442</guid>
      <dc:creator>GustavSandberg</dc:creator>
      <dc:date>2021-06-01T13:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Apostrophe in a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744929#M233444</link>
      <description>&lt;P&gt;Just follow normal quoting rules for how to handle quoted strings that include the quote character.&lt;/P&gt;
&lt;P&gt;1) Use different quoting character on the outside if possible.&lt;/P&gt;
&lt;P&gt;2) Double any quote characters in the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"Action's result"n
'Action''s result'n&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 13:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744929#M233444</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-01T13:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Apostrophe in a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744930#M233445</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had tried option number 1 with no success. Had never seen option number 2 before, and that worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 13:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apostrophe-in-a-variable-name/m-p/744930#M233445</guid>
      <dc:creator>GustavSandberg</dc:creator>
      <dc:date>2021-06-01T13:23:42Z</dc:date>
    </item>
  </channel>
</rss>

