<?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 Proc SQL and multiple variable prompts/counts in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286213#M59477</link>
    <description>&lt;P&gt;Currently on SAS enterprise 7.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new table with Proc SQL that follows two prompts (one to select company, and one to select sector). Company is a single choice and works fine, whereas sector can have multiple variables that need to be included into the table. It will not recognize anything with a count number after, such as &amp;amp;sector_2. I appreciate any help you can provide correcting this syntax.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not super comfortable with macro commands, but I have seen people complete this task with macro's before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using the "case when then else" statement with syntax below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;&lt;BR /&gt;create table Total as&lt;BR /&gt;select L.*, R.*&lt;BR /&gt;from Volumes as L&lt;BR /&gt;LEFT JOIN HDDs as R&lt;BR /&gt;on L.RPT_ST = R.AREA1&lt;BR /&gt;and L.Year = R.Year&lt;BR /&gt;and L.month = R.month&lt;BR /&gt;where comp_id = "&amp;amp;Comp_ID" and &lt;BR /&gt;(case when sector_count=1 then (and L.sector="&amp;amp;sector") else ((Case when (&amp;amp;sector_1 is not null) then (and L.sector="&amp;amp;sector_1")(Case when (&amp;amp;sector_2 is not null) then (and L.sector="&amp;amp;sector_2")end);&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The full command is below and features my second attempt with different syntax that gives me the same errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table Total as
select L.*, R.*
from Volumes as L
LEFT JOIN HDDs as R
on L.RPT_ST = R.AREA1
and L.Year = R.Year
and L.month = R.month
where comp_id = "&amp;amp;Comp_ID" and
Case
When &amp;amp;sector_count = 1 THEN (and L.sector = "&amp;amp;sector")
when &amp;amp;sector_count = 2 Then (and L.sector_1 = "&amp;amp;sector_1")
when &amp;amp;sector_count = 3 Then (and L.sector_2 = "&amp;amp;sector_2")
When &amp;amp;sector_count = 4 THEN (and L.sector_3 = "&amp;amp;sector_3")
when &amp;amp;sector_count = 5 Then (and L.sector_4 = "&amp;amp;sector_4")
when &amp;amp;sector_count = 6 Then (and L.sector_5 = "&amp;amp;sector_5")
When &amp;amp;sector_count = 7 THEN (and L.sector_6 = "&amp;amp;sector_6")
when &amp;amp;sector_count = 8 Then (and L.sector_7 = "&amp;amp;sector_7")
when &amp;amp;sector_count = 9 Then (and L.sector_8 = "&amp;amp;sector_8")
When &amp;amp;sector_count = 10 THEN (and L.sector_9 = "&amp;amp;sector_9")
when &amp;amp;sector_count = 11 Then (and L.sector_10 = "&amp;amp;sector_10")
when &amp;amp;sector_count = 12 Then (and L.sector_11 = "&amp;amp;sector_11")
When &amp;amp;sector_count = 13 THEN (and L.sector_12 = "&amp;amp;sector_12")
when &amp;amp;sector_count = 14 Then (and L.sector_13 = "&amp;amp;sector_13")
when &amp;amp;sector_count = 15 Then (and L.sector_14 = "&amp;amp;sector_14")
When &amp;amp;sector_count = 16 THEN (and L.sector_15 = "&amp;amp;sector_15")
when &amp;amp;sector_count = 17 Then (and L.sector_16 = "&amp;amp;sector_16")
when &amp;amp;sector_count = 18 Then (and L.sector_17 = "&amp;amp;sector_17")
else L.sector = "&amp;amp;sector"
end;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
57 create table Total as
58 select L.*, R.*
59 from Volumes as L
60 LEFT JOIN HDDs as R
61 on L.RPT_ST = R.AREA1
62 and L.Year = R.Year
63 and L.month = R.month
64 where comp_id = "&amp;amp;Comp_ID" and
65 Case
66 When &amp;amp;sector_count = 1 THEN (and L.sector = "&amp;amp;sector")
_
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jul 2016 19:23:01 GMT</pubDate>
    <dc:creator>xezus</dc:creator>
    <dc:date>2016-07-21T19:23:01Z</dc:date>
    <item>
      <title>Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286213#M59477</link>
      <description>&lt;P&gt;Currently on SAS enterprise 7.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a new table with Proc SQL that follows two prompts (one to select company, and one to select sector). Company is a single choice and works fine, whereas sector can have multiple variables that need to be included into the table. It will not recognize anything with a count number after, such as &amp;amp;sector_2. I appreciate any help you can provide correcting this syntax.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not super comfortable with macro commands, but I have seen people complete this task with macro's before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using the "case when then else" statement with syntax below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;&lt;BR /&gt;create table Total as&lt;BR /&gt;select L.*, R.*&lt;BR /&gt;from Volumes as L&lt;BR /&gt;LEFT JOIN HDDs as R&lt;BR /&gt;on L.RPT_ST = R.AREA1&lt;BR /&gt;and L.Year = R.Year&lt;BR /&gt;and L.month = R.month&lt;BR /&gt;where comp_id = "&amp;amp;Comp_ID" and &lt;BR /&gt;(case when sector_count=1 then (and L.sector="&amp;amp;sector") else ((Case when (&amp;amp;sector_1 is not null) then (and L.sector="&amp;amp;sector_1")(Case when (&amp;amp;sector_2 is not null) then (and L.sector="&amp;amp;sector_2")end);&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The full command is below and features my second attempt with different syntax that gives me the same errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table Total as
select L.*, R.*
from Volumes as L
LEFT JOIN HDDs as R
on L.RPT_ST = R.AREA1
and L.Year = R.Year
and L.month = R.month
where comp_id = "&amp;amp;Comp_ID" and
Case
When &amp;amp;sector_count = 1 THEN (and L.sector = "&amp;amp;sector")
when &amp;amp;sector_count = 2 Then (and L.sector_1 = "&amp;amp;sector_1")
when &amp;amp;sector_count = 3 Then (and L.sector_2 = "&amp;amp;sector_2")
When &amp;amp;sector_count = 4 THEN (and L.sector_3 = "&amp;amp;sector_3")
when &amp;amp;sector_count = 5 Then (and L.sector_4 = "&amp;amp;sector_4")
when &amp;amp;sector_count = 6 Then (and L.sector_5 = "&amp;amp;sector_5")
When &amp;amp;sector_count = 7 THEN (and L.sector_6 = "&amp;amp;sector_6")
when &amp;amp;sector_count = 8 Then (and L.sector_7 = "&amp;amp;sector_7")
when &amp;amp;sector_count = 9 Then (and L.sector_8 = "&amp;amp;sector_8")
When &amp;amp;sector_count = 10 THEN (and L.sector_9 = "&amp;amp;sector_9")
when &amp;amp;sector_count = 11 Then (and L.sector_10 = "&amp;amp;sector_10")
when &amp;amp;sector_count = 12 Then (and L.sector_11 = "&amp;amp;sector_11")
When &amp;amp;sector_count = 13 THEN (and L.sector_12 = "&amp;amp;sector_12")
when &amp;amp;sector_count = 14 Then (and L.sector_13 = "&amp;amp;sector_13")
when &amp;amp;sector_count = 15 Then (and L.sector_14 = "&amp;amp;sector_14")
When &amp;amp;sector_count = 16 THEN (and L.sector_15 = "&amp;amp;sector_15")
when &amp;amp;sector_count = 17 Then (and L.sector_16 = "&amp;amp;sector_16")
when &amp;amp;sector_count = 18 Then (and L.sector_17 = "&amp;amp;sector_17")
else L.sector = "&amp;amp;sector"
end;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
57 create table Total as
58 select L.*, R.*
59 from Volumes as L
60 LEFT JOIN HDDs as R
61 on L.RPT_ST = R.AREA1
62 and L.Year = R.Year
63 and L.month = R.month
64 where comp_id = "&amp;amp;Comp_ID" and
65 Case
66 When &amp;amp;sector_count = 1 THEN (and L.sector = "&amp;amp;sector")
_
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 19:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286213#M59477</guid>
      <dc:creator>xezus</dc:creator>
      <dc:date>2016-07-21T19:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286242#M59481</link>
      <description>&lt;P&gt;Before worrying about the prompt did you have a query that worked correctly for multiple hard coded sector values? (Such as testing the code for Sector= 1 and 2 for instance).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get that working and show that and then we may have some ideas on how to use the sector prompt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 19:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286242#M59481</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-21T19:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286246#M59482</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the hard coded, multiple sector run, no errors, everything works fine.&lt;/P&gt;&lt;PRE&gt;54 &lt;BR /&gt;55 proc sql;&lt;BR /&gt;56 create table Total as&lt;BR /&gt;57 select L.*, R.*&lt;BR /&gt;58 from Volumes as L&lt;BR /&gt;59 LEFT JOIN HDDs as R&lt;BR /&gt;60 on L.RPT_ST = R.AREA1&lt;BR /&gt;61 and L.Year = R.Year&lt;BR /&gt;62 and L.month = R.month&lt;BR /&gt;63 where comp_id = "&amp;amp;Comp_ID" and&lt;BR /&gt;64 sector = "DRES" or sector = "DCOM";&lt;BR /&gt;WARNING: Variable YEAR already exists on file WORK.TOTAL.&lt;BR /&gt;WARNING: Variable MONTH already exists on file WORK.TOTAL.&lt;BR /&gt;NOTE: Table WORK.TOTAL created, with 16938 rows and 19 columns.&lt;BR /&gt;&lt;BR /&gt;65 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt; real time 0.03 seconds&lt;BR /&gt; cpu time 0.04 seconds&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 20:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286246#M59482</guid>
      <dc:creator>xezus</dc:creator>
      <dc:date>2016-07-21T20:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286260#M59486</link>
      <description>&lt;P&gt;So it looks like from this:&lt;/P&gt;
&lt;P&gt;sector = "DRES" or sector = "DCOM";&amp;nbsp; (which could have been: sector in ("DRES", "DCOM")&lt;/P&gt;
&lt;P&gt;that you want to turn that sector prompt into a bunch of OR statements or create an IN comparison.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 20:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286260#M59486</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-21T20:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286266#M59487</link>
      <description>&lt;P&gt;Yeah, im trying to have a drop down where I can select one to seventeen different sectors from a menu prompt, which on the prompt side seems to be working fine, the code itself just will not cooperate with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thats why I was trying to do states of "if sector_count = 1 then" blah blah, "if sector_count =2 then" blah blah type of thing. I do not know how to make multiple &amp;amp;sector variables for the prompts. &amp;nbsp;I thought adding the _1 or _xnumber would create itself as a count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So &amp;amp;sector would be the first selected from the list, &amp;amp;sector_1 would be 2nd selected and so forth.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 20:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286266#M59487</guid>
      <dc:creator>xezus</dc:creator>
      <dc:date>2016-07-21T20:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286275#M59489</link>
      <description>&lt;P&gt;Here's an example of creating a new macro variable from your prompt result&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sector = DRES DCOM;
data _null_;
   length r $ 200;
   do i= 1 to countw("&amp;amp;sector");
      r= catx(',',r,quote(scan("&amp;amp;sector",i)));
   end;
   call symputx("newsector",r);
run;

%put &amp;amp;newsector;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It creates a quoted list of comma separated words (assumes NONE of your sector values have spaces in them) in the NEWSECTOR macro variable that can be used as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and sector in (&amp;amp;newsector);&lt;/P&gt;
&lt;P&gt;You wouldn't want to use "&amp;amp;newsector" because of the quotes inside the variable.&lt;/P&gt;
&lt;P&gt;Add the data _null_ step earlier in your process.&lt;/P&gt;
&lt;P&gt;If you have many longer sector names than the displayed one you might need to make the R varaible longer than 200 characters to hold the longest possible list.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 20:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286275#M59489</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-21T20:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286279#M59490</link>
      <description>&lt;P&gt;Thank you so much for your help. I will give this code a try when I get back to my computer in a few hours and let you know how it goes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 21:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286279#M59490</guid>
      <dc:creator>xezus</dc:creator>
      <dc:date>2016-07-21T21:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286473#M59501</link>
      <description>&lt;P&gt;This is definitely getting me closer.&lt;/P&gt;&lt;P&gt;I see it now can generate all of the count variables but I am being presented a new error focused on the macro syntax.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;GOPTIONS NOACCESSIBLE;
112        %LET _CLIENTTASKLABEL=;
ERROR: Open code statement recursion detected.
113        %LET _CLIENTPROJECTPATH=;
ERROR: Open code statement recursion detected.
114        %LET _CLIENTPROJECTNAME=;
ERROR: Open code statement recursion detected.
115        %LET _SASPROGRAMFILE=;
ERROR: Open code statement recursion detected.
116        %SYMDEL Comp_ID;
ERROR: Open code statement recursion detected.
117        %SYMDEL Sector17;
ERROR: Open code statement recursion detected.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Everything I looked up regarding this error seems to think the macro is running another macro within it. &amp;nbsp;the "end;" in your code I would think finished the first macro run, and then allowed the "%put" to operate independently, but it does not seem to agree with me, haha.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2016 20:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286473#M59501</guid>
      <dc:creator>xezus</dc:creator>
      <dc:date>2016-07-22T20:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL and multiple variable prompts/counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286495#M59503</link>
      <description>&lt;P&gt;You've introduced a lot of variables that were not mentioned previously. The OPEN CODE usually occurs when using a macro function that requires it to be inside a %macro / %mend definition such as %IF or %DO and related. Getting an error like that with a simple %let statement makes me believe that there is a lot of code you're not showing. By&amp;nbsp;any chance are you attempting to create a new macro definition using macro variables, i.e. generate a %macro / %mend ?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2016 22:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-and-multiple-variable-prompts-counts/m-p/286495#M59503</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-22T22:00:19Z</dc:date>
    </item>
  </channel>
</rss>

