<?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: Conditionally Import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450967#M113622</link>
    <description>&lt;P&gt;Move the data step from the log of the proc import into the %then-%do-%end block in the macro. Just a copy-paste (remove the line numbers by holding down the alt key while selecting text).&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 08:25:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-04-04T08:25:40Z</dc:date>
    <item>
      <title>Conditionally Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450954#M113615</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have the following issue.&lt;/P&gt;&lt;P&gt;I run a monthly report based on a monthly input file.&lt;/P&gt;&lt;P&gt;IF there is a problem with field Y input file &amp;nbsp;then there is an extra table that we use in order to fix the input file.&lt;/P&gt;&lt;P&gt;How can I tell SAS &amp;nbsp;that IF field Y is Null in all rows then need to import an extra file and then merge input file with repair file in order to fix the field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data &amp;nbsp;Input_tbl;&lt;BR /&gt;input ID X Y;&lt;BR /&gt;cards;&lt;BR /&gt;1 10&amp;nbsp;.&lt;BR /&gt;2 20&amp;nbsp;.&lt;BR /&gt;3 30&amp;nbsp;.&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Reapir_tbl;&lt;BR /&gt;input ID Y;&lt;BR /&gt;cards;&lt;BR /&gt;1 100&lt;BR /&gt;2 200&lt;BR /&gt;3 300&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The import of the repair file is done by proc import&lt;/P&gt;&lt;P&gt;proc import datafile="D:/&lt;SPAN&gt;Reapir&lt;/SPAN&gt;&lt;SPAN&gt;_tbl&lt;/SPAN&gt;.csv"&lt;BR /&gt;out=&lt;SPAN&gt;Reapir&lt;/SPAN&gt;&lt;SPAN&gt;_tbl&lt;/SPAN&gt;&lt;BR /&gt;dbms=csv&lt;BR /&gt;replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 07:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450954#M113615</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-04-04T07:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450955#M113616</link>
      <description>&lt;P&gt;First, if you have a repeating process,&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DO NOT USE PROC IMPORT!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Use proc import once to get a data step, and use that in the future. You will catch structural differences because your data step will fail when the structure changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you simply need to replace "valid" missing values, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data  Input_tbl;
input ID X Y;
cards;
1 10 .
2 20 .
3 30 .
;
run;

Data Repair_tbl;
input ID Y;
cards;
1 100
2 200
3 300
;
run;

%macro check_and_repair;
proc sql noprint;
select max(y) into :y from input_tbl;
quit;

%if &amp;amp;y = . %then %do;

data input_tbl;
merge
  input_tbl
  repair_tbl
;
by id;
run;

%end;
%mend;

%check_and_repair&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I use the proper subwindows for posting code, see &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The main posting window will trash your indentation and do other funny things with code.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 07:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450955#M113616</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-04T07:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450964#M113621</link>
      <description>&lt;P&gt;Perfect and thank you so much.&lt;/P&gt;&lt;P&gt;Just one issue need to add to your code.&lt;/P&gt;&lt;P&gt;When max(y) is null then we need to import the repair file &amp;nbsp;because this file is not in SAS.&lt;/P&gt;&lt;P&gt;As you see it is Conditionally Import because it is done only if&amp;nbsp;&lt;SPAN&gt;max(y) is null.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you please add it to the code you sent?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 08:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450964#M113621</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-04-04T08:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450967#M113622</link>
      <description>&lt;P&gt;Move the data step from the log of the proc import into the %then-%do-%end block in the macro. Just a copy-paste (remove the line numbers by holding down the alt key while selecting text).&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 08:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Import/m-p/450967#M113622</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-04T08:25:40Z</dc:date>
    </item>
  </channel>
</rss>

