<?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 Pass special character name into dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822220#M324665</link>
    <description>&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a filename saved in a variable&lt;/P&gt;
&lt;P&gt;Var1 = Items&amp;amp;20220101&lt;/P&gt;
&lt;P&gt;and I dataset I want to created with the name FullList&lt;/P&gt;
&lt;P&gt;Var2 = FullList&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by doing the below it works:&lt;/P&gt;
&lt;PRE&gt;data FullList;

&amp;nbsp;set&amp;nbsp;Items&amp;amp;20220101;

run;&lt;/PRE&gt;
&lt;P&gt;however when i try using the variable names like the below, it doesnt work:&lt;/P&gt;
&lt;PRE&gt;data Var1,
set Var2;
run;&lt;/PRE&gt;
&lt;P&gt;I have been getting a whole lot of errors when trying various options, e.g. using the quote functions, using str functions, using compress etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 09:10:40 GMT</pubDate>
    <dc:creator>Citrine10</dc:creator>
    <dc:date>2022-07-08T09:10:40Z</dc:date>
    <item>
      <title>Pass special character name into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822220#M324665</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a filename saved in a variable&lt;/P&gt;
&lt;P&gt;Var1 = Items&amp;amp;20220101&lt;/P&gt;
&lt;P&gt;and I dataset I want to created with the name FullList&lt;/P&gt;
&lt;P&gt;Var2 = FullList&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;by doing the below it works:&lt;/P&gt;
&lt;PRE&gt;data FullList;

&amp;nbsp;set&amp;nbsp;Items&amp;amp;20220101;

run;&lt;/PRE&gt;
&lt;P&gt;however when i try using the variable names like the below, it doesnt work:&lt;/P&gt;
&lt;PRE&gt;data Var1,
set Var2;
run;&lt;/PRE&gt;
&lt;P&gt;I have been getting a whole lot of errors when trying various options, e.g. using the quote functions, using str functions, using compress etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 09:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822220#M324665</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-07-08T09:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Pass special character name into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822252#M324682</link>
      <description>&lt;P&gt;For better or worse, this is my impression.&amp;nbsp; It sounds like you are experienced in other programming languages, but not in SAS.&amp;nbsp; It also sounds like you have performed many tests and the multitude of tests and results are starting to blend together.&amp;nbsp; Where I can guide you ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no such thing as a data set name that contains an ampersand.&amp;nbsp; This would never work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; set Items&amp;amp;20220101;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But let's assume that this program would work because the data set Items20220101 actually exists:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FullList;
  set Items20220101;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To treat the data set names as variables, you would need to use macro language.&amp;nbsp; First the warning.&amp;nbsp; You should not do this.&amp;nbsp; To use macro language, you really need more SAS experience.&amp;nbsp; Macro language does not construct a data set, it constructs a program.&amp;nbsp; When the program executes, that is what constructs the data set.&amp;nbsp; It is not a beginner's topic.&amp;nbsp; That said, here's the idea of what could work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var1 = FullList;
%let var2 = Items20220101;
data &amp;amp;var1;
  set &amp;amp;var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro language replaces references to &amp;amp;var1 and &amp;amp;var2 with the strings that they contain.&amp;nbsp; So this does not violate the rule that data set names cannot contain ampersands.&amp;nbsp; Instead, it indicates that macro language needs to replace the references to &amp;amp;var1 and &amp;amp;var2 to identify to SAS what the names of the data sets should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps I have totally mis-identified the problem and you have something else in mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 12:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822252#M324682</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-07-08T12:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Pass special character name into dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822260#M324688</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please show the log you get from both the working code, and non-working code?&amp;nbsp; Do you intend for VAR1 and VAR2 to be macro variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I could not get the code you say is working to work.&amp;nbsp; It's unusual to create a dataset with an &amp;amp; in the name.&amp;nbsp; Apparently it can be done if you turn on ValidMemName=extend.&amp;nbsp; But even with that, you need to use a name literal to reference the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    options validmemname=extend ;
2
3    data FullList;
4     set Items&amp;amp;20220101;
               -
               22
               200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;,
              CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

5    run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FULLLIST may be incomplete.  When this step was stopped there were 0
         observations and 5 variables.
WARNING: Data set WORK.FULLLIST was not replaced because this step was stopped.

6
7    data FullList;
8     set "Items&amp;amp;20220101"n;
9    run;

NOTE: There were 1 observations read from the data set WORK.'ITEMS&amp;amp;20220101'n.
NOTE: The data set WORK.FULLLIST has 1 observations and 0 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 12:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-special-character-name-into-dataset/m-p/822260#M324688</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-07-08T12:55:23Z</dc:date>
    </item>
  </channel>
</rss>

