<?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: Combining text and macro variables in table name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69884#M15141</link>
    <description>For the %DO loop your syntax is off a bit.  Try&lt;BR /&gt;
[pre]%do k = 3 %to 5;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
The syntax for the data set name e.g.&lt;BR /&gt;
[pre] work.&amp;amp;data1.winter [/pre]&lt;BR /&gt;
should be fine provided that &amp;amp;DATA1 resolves tothe first part of your data set name and does not contain trailing blanks.  For instance if &amp;amp;DATA1 contains ALL your data set becomes:&lt;BR /&gt;
[pre] work.ALLwinter [/pre]&lt;BR /&gt;
but who wants to work all winter anyway.</description>
    <pubDate>Fri, 03 Sep 2010 19:35:54 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2010-09-03T19:35:54Z</dc:date>
    <item>
      <title>Combining text and macro variables in table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69880#M15137</link>
      <description>Hi everyone,&lt;BR /&gt;
&lt;BR /&gt;
I'm having a problem with my code that seems trivial, but I've tried every permutation I can think of to no avail.&lt;BR /&gt;
&lt;BR /&gt;
I have one dataset, which I want to break into 4 datasets with a where clause, and then add additional columns.  When I explicitly name the columns, this works fine.  However, my problem has been with the macro variables.&lt;BR /&gt;
&lt;BR /&gt;
This is what I want to do (which doesn't work):&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table work.&amp;amp;data1.winter as&lt;BR /&gt;
select distinct &amp;amp;data1..*,&lt;BR /&gt;
(.....new columns....)&lt;BR /&gt;
from &amp;amp;lib..&amp;amp;data1&lt;BR /&gt;
&lt;BR /&gt;
lib and data1 are inputs.  If I had "create table work.&amp;amp;data1" it would work, and if I had "create table work.winter" it would work; how can I concatenate a macro variable and text within the name of a table?  &lt;BR /&gt;
&lt;BR /&gt;
When I run it in SAS it tells me "Syntax error, expecting one of the following: (, AS, LIKE"&lt;BR /&gt;
&lt;BR /&gt;
Thank you.</description>
      <pubDate>Fri, 03 Sep 2010 17:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69880#M15137</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-03T17:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Combining text and macro variables in table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69881#M15138</link>
      <description>It would be more helpful to actually see &lt;U&gt;all&lt;/U&gt; of the code from the log so we can see exactly where this error of yours is occuring.  It doesn't help to put (.....new columns....) and have part of a SAS error separated from the code.</description>
      <pubDate>Fri, 03 Sep 2010 18:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69881#M15138</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-09-03T18:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combining text and macro variables in table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69882#M15139</link>
      <description>Sorry about that, it's just that it's a fairly large macro.  This is everything preceding the error.&lt;BR /&gt;
&lt;BR /&gt;
%macro pcamacro(indata, lib, all_deps, indvars =, indvars2 =, indvars3 =);&lt;BR /&gt;
proc datasets lib=work kill;&lt;BR /&gt;
   quit;&lt;BR /&gt;
   run;&lt;BR /&gt;
%let j=1;&lt;BR /&gt;
%let data1 = %qscan(&amp;amp;indata, &amp;amp;j);&lt;BR /&gt;
%do %while(&amp;amp;data1 NE);&lt;BR /&gt;
	data &amp;amp;data1;&lt;BR /&gt;
	set &amp;amp;lib..&amp;amp;data1;&lt;BR /&gt;
;&lt;BR /&gt;
%let l=1;&lt;BR /&gt;
%let dep = %scan(&amp;amp;all_deps, &amp;amp;l);&lt;BR /&gt;
%do %while(&amp;amp;dep NE);&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table work.&amp;amp;data1.winter as&lt;BR /&gt;
select distinct &amp;amp;data1..*,&lt;BR /&gt;
avgwind * (jan + feb + decem) as winteravgwind,&lt;BR /&gt;
maxwind * (jan + feb + decem) as wintermaxwind,&lt;BR /&gt;
log(striketotal+1) * (jan + feb + decem) as winterstriketotal,&lt;BR /&gt;
log(maxstriketot+1) * (jan + feb + decem) as wintermaxstriketot,&lt;BR /&gt;
log(raintotal) * (jan + feb + decem) as winterraintotal,&lt;BR /&gt;
log(maxdailyrain) * (jan + feb + decem) as wintermaxdailyrain,&lt;BR /&gt;
avghitemp * (jan + feb + decem) as winteravghitemp,&lt;BR /&gt;
maxhi * (jan + feb + decem) as wintermaxhi,&lt;BR /&gt;
avglotemp * (jan + feb + decem) as winteravglotemp,&lt;BR /&gt;
minlo * (jan + feb + decem) as winterminlo,&lt;BR /&gt;
pressure * (jan + feb + decem) as winterpressure&lt;BR /&gt;
from &amp;amp;lib..&amp;amp;data1&lt;BR /&gt;
where avgwind * (jan + feb + decem) &amp;gt; 0;&lt;BR /&gt;
&lt;BR /&gt;
(same process to try to create spring, summer, fall)&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 03 Sep 2010 18:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69882#M15139</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-03T18:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Combining text and macro variables in table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69883#M15140</link>
      <description>I just heard back from an expert at my company and it looks like using this line instead fixes that problem:&lt;BR /&gt;
&lt;BR /&gt;
%let data1 = %trim(%qscan(&amp;amp;indata, &amp;amp;j));&lt;BR /&gt;
&lt;BR /&gt;
However, I'm still having a similar problem in another part of the code.  I do a factor analysis, and ask it to loop through k:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%do k = 3 %to k = 5;&lt;BR /&gt;
proc factor data=&amp;amp;data1.winter scree nfact=&amp;amp;k rotate=qmin score outstat=&amp;amp;data1.factwinter&amp;amp;k;&lt;BR /&gt;
var winteravgwind wintermaxwind winterstriketotal wintermaxstriketot winterraintotal  &lt;BR /&gt;
wintermaxdailyrain winteravghitemp wintermaxhi winteravglotemp winterminlo winterpressure; &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
It looks like it doesn't produce the output data set.</description>
      <pubDate>Fri, 03 Sep 2010 18:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69883#M15140</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-03T18:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Combining text and macro variables in table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69884#M15141</link>
      <description>For the %DO loop your syntax is off a bit.  Try&lt;BR /&gt;
[pre]%do k = 3 %to 5;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
The syntax for the data set name e.g.&lt;BR /&gt;
[pre] work.&amp;amp;data1.winter [/pre]&lt;BR /&gt;
should be fine provided that &amp;amp;DATA1 resolves tothe first part of your data set name and does not contain trailing blanks.  For instance if &amp;amp;DATA1 contains ALL your data set becomes:&lt;BR /&gt;
[pre] work.ALLwinter [/pre]&lt;BR /&gt;
but who wants to work all winter anyway.</description>
      <pubDate>Fri, 03 Sep 2010 19:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69884#M15141</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-09-03T19:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Combining text and macro variables in table name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69885#M15142</link>
      <description>Thanks!</description>
      <pubDate>Tue, 07 Sep 2010 12:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-text-and-macro-variables-in-table-name/m-p/69885#M15142</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-07T12:10:10Z</dc:date>
    </item>
  </channel>
</rss>

