<?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 Unknown variable name with space query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390232#M93580</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table A, for which I don't know in advance variables names (it can change according to the file I import).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just know I need to access the value of a row where the first column equals something.&lt;/P&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;PRE&gt;SELECT jk INTO :JK1 FROM A WHERE &lt;EM&gt;first_column&lt;/EM&gt; LIKE 'ZZ%'&lt;/PRE&gt;&lt;P&gt;In order to do this I access the name of the first variable and stor it in a macrovariable. The I use it:&lt;/P&gt;&lt;PRE&gt;PROC SQL NOPRINT;
SELECT name INTO : COLUMN1 from SASHELP.VCOLUMN where memname = "A" AND varnum = 1;

SELECT jk INTO :JK1 FROM A
WHERE &amp;amp;COLUMN1. LIKE 'ZZ%';&lt;/PRE&gt;&lt;P&gt;The problem is that usually the variable contains some spaces, like for example "RESULTS CHIR".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried to modify the second query in:&lt;/P&gt;&lt;PRE&gt;SELECT jk INTO :JK1 FROM A
WHERE '&amp;amp;COLUMN1.'n LIKE 'ZZ%';&lt;/PRE&gt;&lt;P&gt;But when I run it the program tells me the column doesn't exist in the contributing table...&lt;/P&gt;&lt;P&gt;Can you help me to resolve this?&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2017 13:40:17 GMT</pubDate>
    <dc:creator>fabdu92</dc:creator>
    <dc:date>2017-08-23T13:40:17Z</dc:date>
    <item>
      <title>Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390232#M93580</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table A, for which I don't know in advance variables names (it can change according to the file I import).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just know I need to access the value of a row where the first column equals something.&lt;/P&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;PRE&gt;SELECT jk INTO :JK1 FROM A WHERE &lt;EM&gt;first_column&lt;/EM&gt; LIKE 'ZZ%'&lt;/PRE&gt;&lt;P&gt;In order to do this I access the name of the first variable and stor it in a macrovariable. The I use it:&lt;/P&gt;&lt;PRE&gt;PROC SQL NOPRINT;
SELECT name INTO : COLUMN1 from SASHELP.VCOLUMN where memname = "A" AND varnum = 1;

SELECT jk INTO :JK1 FROM A
WHERE &amp;amp;COLUMN1. LIKE 'ZZ%';&lt;/PRE&gt;&lt;P&gt;The problem is that usually the variable contains some spaces, like for example "RESULTS CHIR".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I tried to modify the second query in:&lt;/P&gt;&lt;PRE&gt;SELECT jk INTO :JK1 FROM A
WHERE '&amp;amp;COLUMN1.'n LIKE 'ZZ%';&lt;/PRE&gt;&lt;P&gt;But when I run it the program tells me the column doesn't exist in the contributing table...&lt;/P&gt;&lt;P&gt;Can you help me to resolve this?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 13:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390232#M93580</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-08-23T13:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390237#M93581</link>
      <description>&lt;P&gt;Macro variable references within single quotes do not resolve.&amp;nbsp; If you are permitted to use double quotes, switch to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&amp;amp;COLUMN1."n&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if single quotes are required, a more complex expression would do the trick:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%unquote(%str(%'&amp;amp;COLUMN1.%'n))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 13:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390237#M93581</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-23T13:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390238#M93582</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88332"&gt;@fabdu92&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table A, for which I don't know in advance variables names (it can change according to the file I import).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And this is the root of your problem. Deliberately changing variable names are bullshit, &lt;U&gt;and must not be accepted&lt;/U&gt;, period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a clear agreement over the structures of files used to deliver data to your warehouse, and write import code according to those agreements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do NOT use proc import in a production environment. It can be used for prototyping, but that's it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 14:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390238#M93582</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-23T14:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390242#M93584</link>
      <description>&lt;P&gt;Totall agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;here. &amp;nbsp;Any import should be documented and repeatable. &amp;nbsp;From the code you posted, it looks like your taking one piece of information and then putting that into a macro varaible, for use in further code. &amp;nbsp;So, if your basis for not just this but for other code is either unknown, or invalid, all your code will fall down - imagine a square block at the bottom of a tower, if you change that out for a triangle block, it may balance, or it may all collapse regardless of how well the rest of the tower is built.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 14:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390242#M93584</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-23T14:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390245#M93585</link>
      <description>&lt;P&gt;If you are having to do something to the "first column" repeatedly where you don't know the names of your variables tells me the whole process is somewhat suspect.&lt;/P&gt;
&lt;P&gt;If you are using proc import then it is time to learn how to write a data step to read the data so you control the names, the variable types, lengths and formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 14:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390245#M93585</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-23T14:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390291#M93595</link>
      <description>Look at the NLITERAL function to return a valid name. You can also change your options (validvarname=V7) so that variable names cannot have spaces in the first place and not have this issue at all. &lt;BR /&gt;</description>
      <pubDate>Wed, 23 Aug 2017 15:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390291#M93595</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-23T15:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Unknown variable name with space query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390441#M93657</link>
      <description>&lt;P&gt;If your data comes from a delimited file, use option GETNAMES=NO in your import procedure. That way the first column will always be called VAR1.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 22:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unknown-variable-name-with-space-query/m-p/390441#M93657</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-23T22:18:04Z</dc:date>
    </item>
  </channel>
</rss>

