<?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: Pass a SAS array value to Proc SQL as a field name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504868#M1042</link>
    <description>&lt;P&gt;I think this builds the work.asln_prem empty data set, if I understand what you want.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   call execute ("proc sql; create table work.asln_prem
                ( state char(20), cov char(2)");
   cov =  'a g d s h g m n b p q r t ua ub wa wb y';
   stem = 'Prem_wp asln_';
   length varname $ 32;
   do j=1 to countw(stem);
      do i= 1 to countw(cov);
         varname= catx(' ',",",cats(scan(stem,j),scan(cov,i)),'num');
         call execute (varname);

      end;
   end;
   call execute(" ); quit;");
run;
&lt;/PRE&gt;
&lt;P&gt;CALL EXECUTE places lines of code in a buffer to execute after the data step writing them quits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sequence on when things like commas get inserted is somewhat fun. Also note the end of the proc sql after all of the names are created has to close the ) and provide a statement ending ; plus the quit;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Oct 2018 20:17:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-10-16T20:17:44Z</dc:date>
    <item>
      <title>Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504729#M1006</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a fairly new user of SAS and am hoping you can help with a SAS&amp;nbsp;9.4 question. I usually use SAS EG, so am&amp;nbsp;just learning how to program in SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of 19 columns that I'd like to pull from a db2 data server.&amp;nbsp;The column names are identical except for the suffix. I'd like to use a loop to&amp;nbsp;pull the data rather than building 19 different queries, but am not sure how to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've looked through about 20 or so posts and found that I need to create arrays to house the column names...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data define_arrays;
	array cov_list(19) $ a g d s h g m n b p q r t ua ub wa wb y z;
	array wp_list(19) $ ;
	array asln_list(19) $ ;
	do i - 1 to 19;
		wp_list(i) = 'prem_wp_' &amp;amp; cov_list(i);
		asln_list(i) = 'asln_' &amp;amp; cov_list(i);
        end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding is that I need to create a blank table with the desired field names...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WORK.asln_prem 
	(State char(20),
	 Cov char(2),
	 asln num,
	 prem_ep_total num);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a working SQL query to pull the data...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=;
connect to db2 (database='ACTDM5');

create table WORK.asln_prem as 

select * 

from connection to db2
(

SELECT	CASE
		WHEN state IN ('05','55','75') THEN 'California'
	        WHEN state IN ('43','53') THEN 'Texas'
	        WHEN state IN ('32','52') THEN 'New York'
	        WHEN state = '09' THEN 'District of Columbia'
	        ELSE initcap(u92.statename_u(state))
	END AS STATE, 
	double(sum(u92.Ep_auto_annual_u(date_effective_date, date_expiration_date, date_accounting_date, Integer(201712), prem_wp_a))) as prem_ep_total, 
	asln_a as asln,
	'a' as Cov
FROM	v23.auto_prem_v 
WHERE	state not IN( '60','61','64' ) AND
	business_group LIKE 'B01%' AND
	YEAR IN ( 2017, 2016 ) 
GROUP BY 
	state, 
        asln_a 

); 
disconnect from db2;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to modify the above code to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;use the array values&amp;nbsp;in place of the static field names/values&lt;UL&gt;&lt;LI&gt;asln_a replaced by asln_list(i) and used as a field name&lt;/LI&gt;&lt;LI&gt;prem_wp_a replaced by prem_wp_list(i) and used as a field name&lt;/LI&gt;&lt;LI&gt;'a' replaced by cov_list(i) and used as a field value&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;append the data pull to the existing table (work.asln_prem) rather than&amp;nbsp;creating the table&lt;/LI&gt;&lt;LI&gt;run the proc sql 19 times&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help you can provide that will help me make this work. If there's a better&amp;nbsp;approach to take, I'm an eager learner.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 14:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504729#M1006</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-16T14:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504736#M1008</link>
      <description>&lt;P&gt;Arrays are part of data step syntax, they cannot be used in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a select * will pull &lt;EM&gt;all&lt;/EM&gt; columns, anyway.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 14:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504736#M1008</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-16T14:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504742#M1013</link>
      <description>&lt;P&gt;I cannot figure out what your question is.&amp;nbsp; Please show what code you are trying to generate.&lt;/P&gt;
&lt;P&gt;I think you are asking for help writing something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
prem_wp_a,prem_wp_g,prem_wp_d,prem_wp_s
,prem_wp_h,prem_wp_g,prem_wp_m,prem_wp_n
,prem_wp_b,prem_wp_p,prem_wp_q,prem_wp_r
,prem_wp_t,prem_wp_u,prem_wp_u,prem_wp_w
,prem_wp_w,prem_wp_y,prem_wp_z
,asln_a,asln_g,asln_d,asln_s,asln_h,asln_g,asln_m
,asln_n,asln_b,asln_p,asln_q,asln_r,asln_t,asln_u
,asln_u,asln_w,asln_w,asln_y,asln_z
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Oct 2018 14:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504742#M1013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-16T14:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504780#M1021</link>
      <description>&lt;P&gt;Thanks for the responses. it sounds like I can't&amp;nbsp;pass values from a SAS&amp;nbsp;array into an SQL statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here's what I want to do...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Create a table (this works)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WORK.asln_prem 
	(State char(20),
	 Cov char(2),
	 asln num,
	 prem_ep_total num);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;Pull data from an external source and pend it to the table (this also works)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=;

connect to db2 (database='ACTDM5');

insert into work.asln_prem 

select * 

from connection to db2
(

SELECT	CASE
		WHEN state IN ('05','55','75') THEN 'California'
	        WHEN state IN ('43','53') THEN 'Texas'
	        WHEN state IN ('32','52') THEN 'New York'
	        WHEN state = '09' THEN 'District of Columbia'
	        ELSE initcap(u92.statename_u(state))
	END AS STATE, 
	'a' as Cov,
	double(sum(u92.Ep_auto_annual_u(date_effective_date, date_expiration_date, date_accounting_date, Integer(201712), prem_wp_a))) as prem_ep_ttl, 
		int(coalesce(nullif(asln_a,''),'0')) as asln

FROM	v23.auto_prem_v 
WHERE	state not IN( '60','61','64' ) AND
	business_group LIKE 'B01%' AND
	YEAR IN ( 2017, 2016 ) 
GROUP BY 
	state, 
        asln_a 
); 
disconnect from db2;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run the above query 19 times using the following values...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Iteration&amp;nbsp; &amp;nbsp; &amp;nbsp;Cov_code&amp;nbsp; &amp;nbsp;asln_code&amp;nbsp; &amp;nbsp;prem_wp_code&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;asln_a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;perm_wp_a&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;asln_g&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prem_wp_g&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;asln_z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;prem_wp_z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The field values above would replace the fields in the SQL query...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Cov_code replaces 'a'&amp;nbsp;and the SQL uses it as a static value&lt;/LI&gt;&lt;LI&gt;asln_code replaces asln_a and the SQL uses it as a field name to query the external data source and group the data&lt;/LI&gt;&lt;LI&gt;prem_ep_code replaces prem_ep_a and the SQL uses it as a field name to query the external data source&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this make more sense?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 17:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504780#M1021</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-16T17:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504787#M1023</link>
      <description>&lt;P&gt;Please show two versions of your program and hightlight the changes between the two. Not seeing it at the moment.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 17:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504787#M1023</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-16T17:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504791#M1025</link>
      <description>&lt;P&gt;The current version is in my reply. the revised version would look like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=;

connect to db2 (database='ACTDM5');

insert into work.asln_prem 

select * 

from connection to db2
(

SELECT	CASE
		WHEN state IN ('05','55','75') THEN 'California'
	        WHEN state IN ('43','53') THEN 'Texas'
	        WHEN state IN ('32','52') THEN 'New York'
	        WHEN state = '09' THEN 'District of Columbia'
	        ELSE initcap(u92.statename_u(state))
	END AS STATE, 
	&lt;STRONG&gt;&lt;U&gt;&lt;FONT color="#FF0000"&gt;Cov_code&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt; as Cov, /* value of cov_code used as value */
	double(sum(u92.Ep_auto_annual_u(date_effective_date, date_expiration_date, date_accounting_date, Integer(201712), &lt;STRONG&gt;&lt;U&gt;&lt;FONT color="#FF0000"&gt;prem_wp_code&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;))) as prem_ep_ttl, /*value of prem_wp_code used as field name */
		int(coalesce(nullif(&lt;STRONG&gt;&lt;U&gt;&lt;FONT color="#FF0000"&gt;asln_code&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;,''),'0')) as asln /* value of asln_code used as field name */

FROM	v23.auto_prem_v 
WHERE	state not IN( '60','61','64' ) AND
	business_group LIKE 'B01%' AND
	YEAR IN ( 2017, 2016 ) 
GROUP BY 
	state, 
        &lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;asln_code&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt; /* field name */
); 
disconnect from db2;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Oct 2018 17:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504791#M1025</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-16T17:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504868#M1042</link>
      <description>&lt;P&gt;I think this builds the work.asln_prem empty data set, if I understand what you want.&lt;/P&gt;
&lt;PRE&gt;data _null_;
   call execute ("proc sql; create table work.asln_prem
                ( state char(20), cov char(2)");
   cov =  'a g d s h g m n b p q r t ua ub wa wb y';
   stem = 'Prem_wp asln_';
   length varname $ 32;
   do j=1 to countw(stem);
      do i= 1 to countw(cov);
         varname= catx(' ',",",cats(scan(stem,j),scan(cov,i)),'num');
         call execute (varname);

      end;
   end;
   call execute(" ); quit;");
run;
&lt;/PRE&gt;
&lt;P&gt;CALL EXECUTE places lines of code in a buffer to execute after the data step writing them quits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sequence on when things like commas get inserted is somewhat fun. Also note the end of the proc sql after all of the names are created has to close the ) and provide a statement ending ; plus the quit;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 20:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/504868#M1042</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-16T20:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505126#M1100</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hello and thanks again for all of the responses. I guess I still am not being clear on what I'm trying to accomplish. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;In simplest terms, I have a list of 19 suffixes and I want to run the SQL query once for each suffix. The SQL&amp;nbsp;should use the suffix as a field value in one column, and use it as&amp;nbsp;the&amp;nbsp;column name in two of the columns. The end result should be a single table with four columns. As an example, if the suffix is &lt;FONT color="#FF0000"&gt;UA&lt;/FONT&gt; then the query should return the following&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;State&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cov&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PREM_EP_Total&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ASLN&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;California&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;UA&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;value of PREM_EP_&lt;FONT color="#FF0000"&gt;UA&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;value of ASLN_&lt;FONT color="#FF0000"&gt;UA&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;State, PREM_EP_UA, and ASLN_UA are all field names in the query data source.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;The information on the call execute statement really helped me to understand how it was used. I wound up creating something that almost works the way I'd like...runs the query 19 times and creates 19 output tables. I wanted to have all of the&amp;nbsp;information in a single table, but kept getting the following:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ERROR: You cannot open WORK.ASLN_PREM.DATA for output access with member-level control because &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;WORK.ASLN_PREM.DATA is in use by you in resource environment .&lt;/FONT&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;I imagine there's a way to do it, but not savvy enough to figure it out. For now, I'm using a separate append function to add all of the tables together.&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 14:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505126#M1100</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-17T14:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505127#M1101</link>
      <description>&lt;P&gt;Here's a working version of the code that creates the 19 tables. I didn't bother to include the Cov_List datalines&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_;

/* Set static SQL string values */

SQL_Start = "proc sql outobs=;
	connect to db2 (database='ACTDM5');";

SQL_0 = "create table work.asln_";

SQL_1 = " as select * from connection to db2
	( SELECT	CASE
			WHEN state IN ('05','55','75') THEN 'California'
	        WHEN state IN ('43','53') THEN 'Texas'
	        WHEN state IN ('32','52') THEN 'New York'
	        WHEN state = '09' THEN 'District of Columbia'
	        ELSE initcap(u92.statename_u(state))
	END AS STATE, '";

SQL_2 = "' as Cov,
		double(sum(u92.Ep_auto_annual_u(date_effective_date, date_expiration_date, date_accounting_date, Integer(201712), prem_wp_";

SQL_3 = "))) as prem_ep_total, 
		int(coalesce(nullif(asln_";

SQL_4 = ",''),'0')) as asln
	FROM	v23.auto_prem_v 
 	WHERE	state not IN( '60','61','64' ) AND
			business_group LIKE 'B01%' AND
			YEAR IN ( 2017, 2016 )
	GROUP BY state, asln_";

SQL_5 = "); ";

SQL_End = "disconnect from db2;
	quit;";

Set Cov_List end=end_of_data;
SQL_Cov=strip(Cov_T);
call execute( 
	strip(SQL_Start)||
	strip(SQL_0)||SQL_Cov||
	strip(SQL_1)||SQL_Cov||
	strip(SQL_2)||SQL_Cov||
	strip(SQL_3)||SQL_Cov||
	strip(SQL_4)||SQL_Cov||
	strip(SQL_5)||
	strip(SQL_End)
			);	
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 14:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505127#M1101</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-17T14:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505131#M1103</link>
      <description>&lt;P&gt;Here's the version that generates the error&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_;

/* Set static SQL string values */

SQL_Start = "proc sql outobs=;
	connect to db2 (database='ACTDM5');
	create table work.asln_prem as ";

SQL_1 = "select * from connection to db2
	( SELECT	CASE
			WHEN state IN ('05','55','75') THEN 'California'
	        WHEN state IN ('43','53') THEN 'Texas'
	        WHEN state IN ('32','52') THEN 'New York'
	        WHEN state = '09' THEN 'District of Columbia'
	        ELSE initcap(u92.statename_u(state))
	END AS STATE, '";

SQL_2 = "' as Cov,
		double(sum(u92.Ep_auto_annual_u(date_effective_date, date_expiration_date, date_accounting_date, Integer(201712), prem_wp_";

SQL_3 = "))) as prem_ep_total, 
		int(coalesce(nullif(asln_";

SQL_4 = ",''),'0')) as asln
	FROM	v23.auto_prem_v 
 	WHERE	state not IN( '60','61','64' ) AND
			business_group LIKE 'B01%' AND
			YEAR IN ( 2017, 2016 )
	GROUP BY state, asln_";

SQL_5 = ") ";

SQL_Connect = " outer union ";

SQL_End = "; 
	disconnect from db2;
	quit;";

/* initiate the SQL on the first iteration */
if _n_ = 1 then call execute(SQL_Start);

/* disconnect SQL on the last iteration */
else if end_of_data then 
	do;
		call execute(SQL_End);
		stop;
	end;

/* insert union statement between iterations */
else call execute(SQL_Connect);

set Cov_List end=end_of_data;
SQL_Cov=strip(Cov_T);
call execute( 
	strip(SQL_1)||SQL_Cov||
	strip(SQL_2)||SQL_Cov||
	strip(SQL_3)||SQL_Cov||
	strip(SQL_4)||SQL_Cov||
	strip(SQL_5)
			);	
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 14:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505131#M1103</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-17T14:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505138#M1105</link>
      <description>&lt;P&gt;Should have checked the error before posting, as it simply means that the table is still open in the buffer. Closing out of SAS and restarting my system cleared the buffer, so now it work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again everyone for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 15:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505138#M1105</guid>
      <dc:creator>Phuels</dc:creator>
      <dc:date>2018-10-17T15:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a SAS array value to Proc SQL as a field name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505143#M1107</link>
      <description>&lt;P&gt;It would help if you explained in words what the logic of that query is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is it grouping by a value that is NOT in the SELECT list?&lt;/P&gt;
&lt;P&gt;Why is it NOT grouping by a value COV that IS in the select list?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like you could either code this as a series of INSERT statements. Or code it as one large query that UNIONs a series of indvidual sub queries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to simplify that might be to make a little macro that just generates the SELECT statement for one COV value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one(COV);

SELECT
   CASE WHEN state IN ('05','55','75') THEN 'California'
        WHEN state IN ('43','53') THEN 'Texas'
        WHEN state IN ('32','52') THEN 'New York'
        WHEN state = '09' THEN 'District of Columbia'
        ELSE initcap(u92.statename_u(state))
   END AS STATE
 , %bquote('&amp;amp;COV') as Cov
 , int(coalesce(nullif(asln_&amp;amp;COV,''),'0')) as asln
 , double(sum(
   u92.Ep_auto_annual_u(date_effective_date, date_expiration_date
                       ,date_accounting_date, Integer(201712), prem_wp_&amp;amp;COV)
   )) as prem_ep_ttl
FROM v23.auto_prem_v
WHERE state not IN( '60','61','64' )
  AND business_group LIKE 'B01%'
  AND YEAR IN ( 2017, 2016 )
GROUP BY
  state
, cov
, asln

%mend one;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could use it in either structure.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table work.asln as
  select * from connection to db2
  ( %one(A) )
;
insert into work.asln
  select * from connection to db2
  ( %one(B) )
;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table work.asln as
  select * from connection to db2
  ( %one(A) 
     union
     %one(B)
     union .....
)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you wanted you could either then use CALL EXECUTE or macro logic to generate the code above.&lt;/P&gt;
&lt;P&gt;But for your little example of 19 names it might just be easier to use the editor to copy and paste and then change the value passed to the macro call.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 15:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Pass-a-SAS-array-value-to-Proc-SQL-as-a-field-name/m-p/505143#M1107</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-17T15:24:23Z</dc:date>
    </item>
  </channel>
</rss>

