<?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: Using prompts with if then else in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494965#M130547</link>
    <description>made the change, thank you for correcting.</description>
    <pubDate>Wed, 12 Sep 2018 18:37:56 GMT</pubDate>
    <dc:creator>astha8882000</dc:creator>
    <dc:date>2018-09-12T18:37:56Z</dc:date>
    <item>
      <title>Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494944#M130529</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to learn how to use prompts in SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have prompt set up as 'prompt_1' which can either have value of Year1 or Yearly. I have a couple of proc sql and data set statements that need to run only if the prompt_1 value is Year1. Please find the code, it gives no errors, but I get no output either. Please suggest what am I doing wrong.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
%put &amp;amp;prompt_1.; 
prompt_1 = "&amp;amp;prompt_1."; 
run;

&amp;nbsp;


%macro determinecall(prompt_1);
%if %upcase(prompt_1) = 'YEAR1' %then %GO; 
%mend determinecall;
%determinecall(prompt_1);


%macro GO;
proc printto log= "/sasuserhome/test/test.log";
run;
proc sql;
create table paylist
(IdNum char(4),
Gender char(1),
Jobcode char(3),

insert into paylist
values('1639','F','TA1')
values('1065','M','ME3'); 
select *
from paylist;
quit;

data alpha;
infile datalines;
input a b c;

datalines;
1 5 10
0 8 7
1 4 6
;
run;

proc print data= alpha;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494944#M130529</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494948#M130532</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%upcase&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;prompt_1&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;YEAR1&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try removing the quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122200"&gt;@astha8882000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to learn how to use prompts in SAS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have prompt set up as 'prompt_1' which can either have value of Year1 or Yearly. I have a couple of proc sql and data set statements that need to run only if the prompt_1 value is Year1. Please find the code, it gives no errors, but I get no output either. Please suggest what am I doing wrong.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
%put &amp;amp;prompt_1.; 
prompt_1 = "&amp;amp;prompt_1."; 
run;

&amp;nbsp;


%macro determinecall(prompt_1);
%if %upcase(prompt_1) = 'YEAR1' %then %GO; 
%mend determinecall;
%determinecall(prompt_1);


%macro GO;
proc printto log= "/sasuserhome/test/test.log";
run;
proc sql;
create table paylist
(IdNum char(4),
Gender char(1),
Jobcode char(3),

insert into paylist
values('1639','F','TA1')
values('1065','M','ME3'); 
select *
from paylist;
quit;

data alpha;
infile datalines;
input a b c;

datalines;
1 5 10
0 8 7
1 4 6
;
run;

proc print data= alpha;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494948#M130532</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-12T18:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494951#M130534</link>
      <description>Tried doing that too, still no output.</description>
      <pubDate>Wed, 12 Sep 2018 18:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494951#M130534</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494953#M130535</link>
      <description>&lt;P&gt;Is this the code you would actually want to use? I'm not sure you can create tables that way with PROC SQL, I know you can't use CARDS/DATALINES in a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you checked the value of your parameters using %PUT statements?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Check the condition execution with %PUT?&lt;/P&gt;
&lt;P&gt;Use MPRINT/SYMBOLGEN to see what's happening.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494953#M130535</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-12T18:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494955#M130537</link>
      <description>&lt;P&gt;First check what is in the macro variable. You could use this macro statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=prompt_1 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you want to use data step code then something like this.&amp;nbsp; Added the $QUOTE format will put quotes around the value in the log to make it easier to see if the value had leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   length prompt_1 $100 ;
   prompt_1 = symget('prompt_1');
   put prompt_1 = :$quote. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In general to test a value in macro code you do not want to add quotes since the quotes will be part of the value.&lt;/P&gt;
&lt;P&gt;So if PROMPT_1 has Year1 in it then you need to test in macro logic like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;prompt_1 = Year1 %then ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if "&amp;amp;prompt_1" = "Year1" %then ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might need to make sure the case is right.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %qupcase(&amp;amp;prompt_1) = YEAR1 %then ....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494955#M130537</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-12T18:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494956#M130538</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table paylist&lt;BR /&gt;(IdNum char(4),&lt;BR /&gt;Gender char(1),&lt;BR /&gt;Jobcode char(3))&amp;nbsp;&lt;STRONG&gt; /*notice the correction here*/&lt;/STRONG&gt;&lt;BR /&gt;;&lt;BR /&gt;insert into paylist&lt;BR /&gt;values('1639','F','TA1')&lt;BR /&gt;values('1065','M','ME3'); &lt;BR /&gt;select *&lt;BR /&gt;from paylist;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494956#M130538</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-12T18:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494957#M130539</link>
      <description>As of now I'm just trying to identify why my macro GO is not being called. Had my macro been called, I'm pretty sure proc sql statements would have caused errors.</description>
      <pubDate>Wed, 12 Sep 2018 18:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494957#M130539</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494959#M130541</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122200"&gt;@astha8882000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;As of now I'm just trying to identify why my macro GO is not being called. Had my macro been called, I'm pretty sure proc sql statements would have caused errors.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could it be because you trying to run the first macro (the one that calls %GO()) before you actually defined the GO macro?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494959#M130541</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-12T18:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494961#M130543</link>
      <description>I checked the value of prompt_1 and it does contain Year1&lt;BR /&gt;&lt;BR /&gt;I also updated the if statement to %if &amp;amp;prompt_1 = Year1 %then&lt;BR /&gt;&lt;BR /&gt;But I still get no output, not sure why GO is not being called.&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494961#M130543</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494963#M130545</link>
      <description>I moved the GO macro above the determinecall macro, still no output.</description>
      <pubDate>Wed, 12 Sep 2018 18:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494963#M130545</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494964#M130546</link>
      <description>&lt;P&gt;coz like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;says your macro GO is not yet compiled for execution when you execute %determinecall&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you can't have datalines code in a macro definition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then your sql syntax needs to be corrected as I posted previously&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494964#M130546</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-12T18:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494965#M130547</link>
      <description>made the change, thank you for correcting.</description>
      <pubDate>Wed, 12 Sep 2018 18:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494965#M130547</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494968#M130548</link>
      <description>I moved the GO macro definition before the determinecall macro definition, but that didn't help either.&lt;BR /&gt;For the datalines, once my macro gets called, I'm pretty sure I will get an error for that.</description>
      <pubDate>Wed, 12 Sep 2018 18:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494968#M130548</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-12T18:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494969#M130549</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods listing;

%macro TEST_MACRO;
proc print data= sashelp.class;
run;
%mend;

%macro determinecall(prompt_1);
%if %upcase(&amp;amp;prompt_1) = YEAR1 %then %test_macro; 
%mend determinecall;






%let prompt_1 = YEAR1;
%determinecall(&amp;amp;prompt_1);

%let prompt_1 = YEAR2;
%determinecall(&amp;amp;prompt_1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, let's go through your code, see the comments below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that GO is also a reserved word, so you shouldn't use that as a macro name.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p0y43hj7lzhq1gn1r68h65wzljbt.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p0y43hj7lzhq1gn1r68h65wzljbt.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
%put &amp;amp;prompt_1.; 
prompt_1 = "&amp;amp;prompt_1.";  *this line doesn't do anything;
run;

 


%macro determinecall(prompt_1); *here you reference a new value prompt_1 but it's local to the macro, not your macro variable;

*In this line you forgot the &amp;amp; to resolve the macro variable and you need to remove quotes;
%if %upcase(prompt_1) = 'YEAR1' %then %GO;  *%GO macro has not be defined yet, not sure if that's an issue, but logically it seems to be;
%mend determinecall;

*calling it here without an actual value since no ampersand;
%determinecall(prompt_1);


%macro GO;
proc printto log= "/sasuserhome/test/test.log";
run;

*not sure SAS macros ccan create tables like this;
proc sql;
create table paylist
(IdNum char(4),
Gender char(1),
Jobcode char(3),

insert into paylist
values('1639','F','TA1')
values('1065','M','ME3'); 
select *
from paylist;
quit;

*this is definitely invalid in a macro;
*datalines dont run;
data alpha;
infile datalines;
input a b c;

datalines;
1 5 10
0 8 7
1 4 6
;
run;

proc print data= alpha;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/494969#M130549</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-12T18:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using prompts with if then else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/495449#M130756</link>
      <description>I made the changes like you suggested, and I think it works. I'm going to try on another code which is a huge list of proc sqls and data _null statements and see if it works for that too. Thank you so much for your help!!</description>
      <pubDate>Thu, 13 Sep 2018 18:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-prompts-with-if-then-else/m-p/495449#M130756</guid>
      <dc:creator>astha8882000</dc:creator>
      <dc:date>2018-09-13T18:26:04Z</dc:date>
    </item>
  </channel>
</rss>

