<?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: How to combine an if statement with datalines in a data step in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647968#M36031</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You already have some nice hints for your issue but let me share one more: PARMCARDS&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename XYZ temp;
options PARMCARDS=XYZ; 
PARMCARDS4;
1
2
3
;;;;

filename noXYZ temp;
options PARMCARDS=noXYZ; 
PARMCARDS4;
4
5
6
;;;;


%let m = ABC;
data test;
if "&amp;amp;m." = "XYZ" then infile XYZ;
                 else infile noXYZ;
input x;
run;
proc print data = test;
run;


%let m = XYZ;
data test;
if "&amp;amp;m." = "XYZ" then infile XYZ;
                 else infile noXYZ;
input x;
run;
proc print data = test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Fri, 15 May 2020 05:24:41 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-05-15T05:24:41Z</dc:date>
    <item>
      <title>How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647727#M36019</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to read in data with datalines in a data step. The input via datalines should be, however, depending on a macro variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myVar = XYZ;
data test;
 input z;
 if "&amp;amp;myVar." eq "XYZ" then do;
  datalines;
1
2
3
;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get an error: "There was 1 unclosed DO block".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I do the math, I have 1 DO statement and 1 end statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have an idea? I know that I could do it with a macro but somehow I prefer that setup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best!&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 09:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647727#M36019</guid>
      <dc:creator>AndreasF</dc:creator>
      <dc:date>2020-05-14T09:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647728#M36020</link>
      <description>&lt;P&gt;What is the goal here? This is definitely not the right setup &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Do you want to read all the data only if the macro variable is equal to some value? And what if it is not?&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 09:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647728#M36020</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-05-14T09:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647729#M36021</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122974"&gt;@AndreasF&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would this solution solve your problem ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myVar = XYZ;

data test;
	input z;
	if "&amp;amp;myVar." eq "XYZ" then output;
	datalines;
1
2
3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 09:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647729#M36021</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-14T09:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647732#M36022</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your fast response. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I should be more precise in the example. If a variable has a certain value, some data should be read in with datalines, else different data should be read in:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myVar = XYZ;
data test;
 input z;
 if "&amp;amp;myVar." eq "XYZ" then do;
  datalines;
1
2
3
;
  end;
else do;
  datalines;
4
5
6
;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 09:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647732#M36022</guid>
      <dc:creator>AndreasF</dc:creator>
      <dc:date>2020-05-14T09:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647742#M36023</link>
      <description>&lt;P&gt;Since SAS 9.4M6 (or M5?), %if-%then %do-%end can be used in open code, and you can conditionally feed your datalines block to the interpreter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myVar = XYZ;
data test;
input z;
%if  &amp;amp;myVar. eq XYZ %then %do;
datalines;
1
2
3
;
%end;
%if &amp;amp;myVar. ne XYZ %then %do;;
datalines;
4
5
6
;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 10:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647742#M36023</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-14T10:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647743#M36024</link>
      <description>&lt;P&gt;Why you must use macro code here:&lt;/P&gt;
&lt;P&gt;the DATALINES statement ends the data step; what follows can only be only data, and the DATALINES statement must always be the last statement of your data step code. So you cannot wrap a data step do/end &lt;EM&gt;around&lt;/EM&gt; it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Up to the most recent SAS versions, it would not have been possible to do that, as you would have needed a macro definition, and datalines can't be used in a macro; similarly, macro triggers are not resolved in a datalines block. But the addition of %if in open code has made it possible to use conditional datalines blocks.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 10:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647743#M36024</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-14T10:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647798#M36025</link>
      <description>&lt;P&gt;A data step can have one datalines block.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647798#M36025</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-14T13:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647800#M36026</link>
      <description>OK. Massive bug in SAS or at least they didn't think it through. Thanks anyways.</description>
      <pubDate>Thu, 14 May 2020 13:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647800#M36026</guid>
      <dc:creator>AndreasF</dc:creator>
      <dc:date>2020-05-14T13:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647801#M36027</link>
      <description>&lt;P&gt;Just because &lt;EM&gt;you&lt;/EM&gt; think it should work differently, it is NOT a bug. In fact it makes perfect sense, once you're familiar with the workings of a data step. It is of course &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p0114gachtut3nn1and4ap8ke9nf.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;properly documented&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can put ANYTHING into a datalines block, including things that usually would be interpreted as data step code or macro code. Therefore the restrictions.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647801#M36027</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-14T13:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647816#M36028</link>
      <description>&lt;P&gt;So you want to use different data based on the value of a macro variable?&lt;/P&gt;
&lt;P&gt;Since the macro processor is used to dynamically generate code just use it to dynamically generate the code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there is no need to change the DATALINES.&amp;nbsp; Either create two datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
  input z;
datalines;
1
2
3
;
data not_xyz;
  input z;
datalines;
4
5
6
;

%let myvar=xyz;
data want;
  set &amp;amp;myvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or make one dataset with two different groups of data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_data;
  input group $ @;
  do until(z=.) ;
     input z @;
     if z ne . then output;
  end;
cards;
XYZ 1 2 3 .
NOT_XYZ 4 5 6 .
;

data want ;
   set test_data;
   where group = "&amp;amp;myvar";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 14:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647816#M36028</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-14T14:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine an if statement with datalines in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647968#M36031</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You already have some nice hints for your issue but let me share one more: PARMCARDS&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename XYZ temp;
options PARMCARDS=XYZ; 
PARMCARDS4;
1
2
3
;;;;

filename noXYZ temp;
options PARMCARDS=noXYZ; 
PARMCARDS4;
4
5
6
;;;;


%let m = ABC;
data test;
if "&amp;amp;m." = "XYZ" then infile XYZ;
                 else infile noXYZ;
input x;
run;
proc print data = test;
run;


%let m = XYZ;
data test;
if "&amp;amp;m." = "XYZ" then infile XYZ;
                 else infile noXYZ;
input x;
run;
proc print data = test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 05:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-combine-an-if-statement-with-datalines-in-a-data-step/m-p/647968#M36031</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-15T05:24:41Z</dc:date>
    </item>
  </channel>
</rss>

