<?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 extract data from a data source given more data sources and a staging table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917881#M361570</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77934"&gt;@mmohotsi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Extracting the data for each record (request) on the staging table is doable and then interrogating the data sets individually. In my case, the staging table is not constant.&amp;nbsp; I have two customers who complete the information on the staging table at any given time.&amp;nbsp; So, I thought of requesting SAS to &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;automatically&lt;/STRONG&gt; &lt;/EM&gt;&lt;/U&gt;read the staging table and if it finds only one record (request) then SAS should extract the data and generate a report. If it finds two records (requests) then SAS should generate two distinct data sets for each row (request) and then generate a report for each record (request).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You didn't share sample code for report generation but the bit that creates table(s) based on what's in source variable Data1 is what the code I shared is doing - and which is basically the logic of the code you shared with some improvements.&lt;/P&gt;
&lt;P&gt;This code is data driven (automatic) so not really sure what's missing for you. Is the code you shared something you developed or was that just a copy/paste and you actually don't really understand what and how it generates code?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2024 08:55:22 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-02-26T08:55:22Z</dc:date>
    <item>
      <title>How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917312#M361343</link>
      <description>&lt;P&gt;I am trying to extract data from a data source given conditions from a staging table. The staging table has more than 1 record and I therefore have to select the appropriate data source between data sources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;filename EXECU1&lt;/DIV&gt;
&lt;DIV&gt;TEMP;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%macro Raw_Data;&lt;/DIV&gt;
&lt;DIV&gt;data _null_;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;file EXECU1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; set CUSTOMER_FRAME33;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;IF REPORT_NAME = 'ZUIKERBOSCH_DR' THEN DO;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "proc sql; " / "create table " Data1 " as&amp;nbsp; &amp;nbsp;" / "&amp;nbsp; select SAMPLE.SAMPLE_NUMBER, SAMPLE.PARENT_ALIQUOT, SAMPLE.SAMPLING_POINT, SAMPLE.ORIGINAL_SAMPLE,&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; SAMPLE.SAMPLED_DATE, RESULT.NAME, RESULT.FORMATTED_ENTRY,RESULT.UNITS,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; RESULT.NUMERIC_ENTRY, RESULT.STATUS,RESULT.REPORTABLE, RESULT_NUMBER";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put " from datasource1.sample, VGSQL1.datasource1" / " where sample.sample_number=result.sample_number and" / " sample.sampled_date between ";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "'"&amp;nbsp; start_date +(-1) "'d and" ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "'"&amp;nbsp; end_date&amp;nbsp; &amp;nbsp; "'d";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "and sample.sampling_point in "&amp;nbsp; SAMPLING_POINTS" and " / "&amp;nbsp; RESULT.name in "&amp;nbsp; DETERMINANDS" and " ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "result.status = 'A' and " / " result.reportable = 'T' and " / " parent_aliquot ne 0;" ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;;END;ELSE&lt;/DIV&gt;
&lt;DIV&gt;IF REPORT_NAME = 'ZUIKERBOSCH_RD' THEN DO;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "proc sql; " / "create table " Data1 " as&amp;nbsp; &amp;nbsp;" / "&amp;nbsp; select SAMPLE.SAMPLE_NUMBER, SAMPLE.PARENT_ALIQUOT, SAMPLE.SAMPLING_POINT, SAMPLE.ORIGINAL_SAMPLE,&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; SAMPLE.SAMPLED_DATE, RESULT.NAME, RESULT.FORMATTED_ENTRY,RESULT.UNITS,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; RESULT.NUMERIC_ENTRY, RESULT.STATUS,RESULT.REPORTABLE, RESULT_NUMBER";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put " from datasource2.sample, datasource2.result" / " where sample.sample_number=result.sample_number and" / " sample.sampled_date between ";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "'"&amp;nbsp; start_date +(-1) "'d and" ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "'"&amp;nbsp; end_date&amp;nbsp; &amp;nbsp; "'d";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "and sample.sampling_point in "&amp;nbsp; SAMPLING_POINTS" and " / "&amp;nbsp; RESULT.name in "&amp;nbsp; DETERMINANDS" and " ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;put "result.status = 'A' and " / " result.reportable = 'T' and " / " parent_aliquot ne 0;" ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;;END;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%include EXECU1;&lt;/DIV&gt;
&lt;DIV&gt;%mend Raw_Data;&lt;/DIV&gt;
&lt;DIV&gt;%Raw_Data;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I get two errors as follows:&lt;/DIV&gt;
&lt;DIV&gt;&lt;BR /&gt;ERROR: Cannot open %INCLUDE file EXECU1.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;P&gt;;*';*";*/;quit;run;&lt;BR /&gt;____&lt;BR /&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 22 Feb 2024 07:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917312#M361343</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2024-02-22T07:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917321#M361349</link>
      <description>&lt;P&gt;Ideally use the running man icon here in the forum for sharing code because this maintains your source formatting.&lt;/P&gt;
&lt;P&gt;I find it during development easiest to first PRINT generated code (file print) and then copy/paste the this code into a code window for execution. This then helps me to easier spot syntax errors in the generated code.&lt;/P&gt;
&lt;P&gt;I find it also worth to put in the bit of extra effort for creation of a somewhat "clean" code structure with line breaks and indention for both the code generation script as well as for the generated code. You get the payback when it comes to debugging and maintenance.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options ls=max ps=max;

libname src 'c:\temp';
data CUSTOMER_FRAME33;
  set src.CUSTOMER_FRAME33;
run;

options ls=max ps=max;
filename EXECU1 TEMP;

data _null_;
/*  file EXECU1;*/
  file print;
  set CUSTOMER_FRAME33;

  if REPORT_NAME in ('ZUIKERBOSCH_DR','ZUIKERBOSCH_RD') then
    do;
      put
        "proc sql; " / 
        "  create table " Data1 "as" / 
        "  select" /
        "    t1.sample_number," /
        "    t1.parent_aliquot," /
        "    t1.sampling_point," /
        "    t1.original_sample," /
        "    t1.sampled_date," /
        "    t2.name," /
        "    t2.formatted_entry," /
        "    t2.units," /
        "    t2.numeric_entry," /
        "    t2.status," /
        "    t2.reportable," /
        "    result_number" /
        ;

      IF REPORT_NAME = 'ZUIKERBOSCH_DR' THEN
        put "  from datasource1.sample t1, VGSQL1.datasource1 t2";
      ELSE IF REPORT_NAME = 'ZUIKERBOSCH_RD' THEN
        put "  from datasource2.sample t1, datasource2.result t2";

      put 
        "  where t1.sample_number=t2.sample_number" / 
        "   and t1.sampled_date between '" start_date date9. "'d and '" end_date date9. "'d" /
        "   and t1.sampling_point in " SAMPLING_POINTS /
        "   and t2.name in " DETERMINANDS /
        "   and t2.status = 'A' " /
        "   and t2.reportable = 'T' " /
        "   and parent_aliquot ne 0;" /
        " quit;"
        ;
    end;
run;

/*%include EXECU1 /source2;*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Above generates the following SQL with the sample data you've shared. You now can unit test &amp;amp; debug this sample code and potentially then amend the code generation bit based on your findings.&lt;/P&gt;
&lt;PRE&gt;proc sql;                                                                                                                                                                                                                                                       
  create table DATA_RAW as                                                                                                                                                                                                                                      
  select                                                                                                                                                                                                                                                        
    t1.sample_number,                                                                                                                                                                                                                                           
    t1.parent_aliquot,                                                                                                                                                                                                                                          
    t1.sampling_point,                                                                                                                                                                                                                                          
    t1.original_sample,                                                                                                                                                                                                                                         
    t1.sampled_date,                                                                                                                                                                                                                                            
    t2.name,                                                                                                                                                                                                                                                    
    t2.formatted_entry,                                                                                                                                                                                                                                         
    t2.units,                                                                                                                                                                                                                                                   
    t2.numeric_entry,                                                                                                                                                                                                                                           
    t2.status,                                                                                                                                                                                                                                                  
    t2.reportable,                                                                                                                                                                                                                                              
    result_number                                                                                                                                                                                                                                               
  from datasource2.sample t1, datasource2.result t2                                                                                                                                                                                                             
  where t1.sample_number=t2.sample_number                                                                                                                                                                                                                       
   and t1.sampled_date between '01APR2023'd and '26APR2023'd                                                                                                                                                                                                    
   and t1.sampling_point in                                                                                                                                                                                                                                     
   and t2.name in                                                                                                                                                                                                                                               
   and t2.status = 'A'                                                                                                                                                                                                                                          
   and t2.reportable = 'T'                                                                                                                                                                                                                                      
   and parent_aliquot ne 0;                                                                                                                                                                                                                                     
 quit;                                                                                                                                                                                                                                                          
proc sql;                                                                                                                                                                                                                                                       
  create table DATA_RAW as                                                                                                                                                                                                                                      
  select                                                                                                                                                                                                                                                        
    t1.sample_number,                                                                                                                                                                                                                                           
    t1.parent_aliquot,                                                                                                                                                                                                                                          
    t1.sampling_point,                                                                                                                                                                                                                                          
    t1.original_sample,                                                                                                                                                                                                                                         
    t1.sampled_date,                                                                                                                                                                                                                                            
    t2.name,                                                                                                                                                                                                                                                    
    t2.formatted_entry,                                                                                                                                                                                                                                         
    t2.units,                                                                                                                                                                                                                                                   
    t2.numeric_entry,                                                                                                                                                                                                                                           
    t2.status,                                                                                                                                                                                                                                                  
    t2.reportable,                                                                                                                                                                                                                                              
    result_number                                                                                                                                                                                                                                               
  from datasource1.sample t1, VGSQL1.datasource1 t2                                                                                                                                                                                                             
  where t1.sample_number=t2.sample_number                                                                                                                                                                                                                       
   and t1.sampled_date between '01JAN2024'd and '19JAN2024'd                                                                                                                                                                                                    
   and t1.sampling_point in ("M-BG1","M-B8","M-B7","M-B6","M-B4","M-B2")                                                                                                                                                                                        
   and t2.name in ("Turb","Colour")                                                                                                                                                                                                                             
   and t2.status = 'A'                                                                                                                                                                                                                                          
   and t2.reportable = 'T'                                                                                                                                                                                                                                      
   and parent_aliquot ne 0;                                                                                                                                                                                                                                     
 quit;              &lt;/PRE&gt;
&lt;P&gt;Ideally also define the source table in below two code sections (it wasn't in your code so I can't know):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1708596533339.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93998i0DB0D96CA42B3961/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1708596533339.png" alt="Patrick_0-1708596533339.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1708596566725.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93999iA3D23A5FC1A40F3D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1708596566725.png" alt="Patrick_1-1708596566725.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 10:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917321#M361349</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-22T10:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917332#M361356</link>
      <description>&lt;P&gt;Result_number is from t2 whilst parent_aliquot is from t1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I previously used the code below to extract data when the source table was to have only one record.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;filename EXECU1&lt;/DIV&gt;
&lt;DIV&gt;TEMP;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data _null_;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;file EXECU1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; set CUSTOMER_FRAME33;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "proc sql; " / "create table " Data1 " as&amp;nbsp; &amp;nbsp;" / "&amp;nbsp; select SAMPLE.SAMPLE_NUMBER, SAMPLE.PARENT_ALIQUOT, SAMPLE.SAMPLING_POINT, SAMPLE.ORIGINAL_SAMPLE,&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; SAMPLE.SAMPLED_DATE, RESULT.NAME, RESULT.FORMATTED_ENTRY,RESULT.UNITS,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; RESULT.NUMERIC_ENTRY, RESULT.STATUS,RESULT.REPORTABLE, RESULT_NUMBER";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put " from datasource1.sample, datasource1.result" / " where sample.sample_number=result.sample_number and" / " sample.sampled_date between ";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "'"&amp;nbsp; start_date +(-1) "'d and" ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "'"&amp;nbsp; end_date&amp;nbsp; &amp;nbsp; "'d";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "and sample.sampling_point in "&amp;nbsp; SAMPLING_POINTS" and " / "&amp;nbsp; RESULT.name in "&amp;nbsp; DETERMINANDS" and " ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; put "result.status = 'A' and " / " result.reportable = 'T' and " / " parent_aliquot ne 0;" / " quit;";&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;%include EXECU1;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;It now shows that with the staging table that I included in the topic, any of the two records can be found in the staging table. The aim will therefore be to ask SAS to read the staging table and extract data based on the record that in on the staging table. The unique field that identifies the record is REPORT_NAME.&lt;/DIV&gt;
&lt;DIV&gt;I therefore thought that a macro can be used to make such a request for SAS to execute.&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 10:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917332#M361356</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2024-02-22T10:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917355#M361368</link>
      <description>&lt;P&gt;You would create the file EXECU1 once the macro&amp;nbsp;&lt;EM&gt;executes&lt;/EM&gt;, but you include the file already during the&amp;nbsp;&lt;EM&gt;definition&lt;/EM&gt; of the macro, so this cannot work.&lt;/P&gt;
&lt;P&gt;Your macro has no parameter, and nowhere in the code do you make use of a macro variable to make code dynamic. All controlling information is in the dataset, which means you do not need the macro at all. Remove the %MACRO and %MEND statements, and the macro call. Start a new SAS session (the failed run caused an unstable state), and run the reduced code.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 13:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917355#M361368</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-22T13:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917357#M361369</link>
      <description>&lt;P&gt;If your dataset has multiple observations, use a WHERE to select one, if you want only one execution in EXECU1.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 13:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917357#M361369</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-22T13:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917365#M361376</link>
      <description>Hi Kurt_Bremser&lt;BR /&gt;The reduced code works for a single record from the staging table. In this case the table may have any of the two record that have the unique variable REPORT_NAME on the staging table. So I need SAS to either extract data when there is one of the records on the staging table or both(the records).&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Feb 2024 14:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917365#M361376</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2024-02-22T14:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917377#M361379</link>
      <description>&lt;P&gt;The DATA _NULL_ step reads&amp;nbsp;&lt;U&gt;all&lt;/U&gt; observations from the controlling dataset and will write code for&amp;nbsp;&lt;U&gt;all&lt;/U&gt; into the file. When the file is included, the generated steps will run one by one.&lt;/P&gt;
&lt;P&gt;Where is the issue?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 15:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917377#M361379</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-22T15:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917427#M361395</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77934"&gt;@mmohotsi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Kurt_Bremser&lt;BR /&gt;The reduced code works for a single record from the staging table. In this case the table may have any of the two record that have the unique variable REPORT_NAME on the staging table. So I need SAS to either extract data when there is one of the records on the staging table or both(the records).&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not clear at all what you mean.&amp;nbsp; You have code being generated from DATA.&amp;nbsp; The code is using the value of a variable named DATA1 to create the dataset name that is being created.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"create table " Data1 " as   "&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if the source data has multiple observations for the same value of DATA1 then you will end up writing two steps both create the same dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what do you want to do in that situation?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show the code you want generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want the selection criteria to include multiple conditions that should be OR'd?&lt;/P&gt;
&lt;P&gt;Do you want to generate one step that pulls data using difference selection criteria?&lt;/P&gt;
&lt;P&gt;Do you want to generate multiple files and then combine them?&amp;nbsp; Look into using PROC APPEND.&amp;nbsp; Or since you seem to be generating SQL code instead of SAS code perhaps only the first step for a value of DATA1 would use CREATE TABLE and the other steps generated should use INSERT INTO instead.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 19:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917427#M361395</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-22T19:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917451#M361405</link>
      <description>&lt;P&gt;I've used what you call "staging" table as the driver for code generation. The sample you've shared got two rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each row in this "staging" table a separate Proc SQL will get created which I shared as well. Is this not what you want? If not then can you please explain what should happen? Which row from the "staging" table should get used for code generation?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 21:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917451#M361405</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-22T21:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917879#M361568</link>
      <description>&lt;P&gt;Extracting the data for each record (request) on the staging table is doable and then interrogating the data sets individually. In my case, the staging table is not constant.&amp;nbsp; I have two customers who complete the information on the staging table at any given time.&amp;nbsp; So, I thought of requesting SAS to &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;automatically&lt;/STRONG&gt; &lt;/EM&gt;&lt;/U&gt;read the staging table and if it finds only one record (request) then SAS should extract the data and generate a report. If it finds two records (requests) then SAS should generate two distinct data sets for each row (request) and then generate a report for each record (request).&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 08:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917879#M361568</guid>
      <dc:creator>mmohotsi</dc:creator>
      <dc:date>2024-02-26T08:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract data from a data source given more data sources and a staging table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917881#M361570</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77934"&gt;@mmohotsi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Extracting the data for each record (request) on the staging table is doable and then interrogating the data sets individually. In my case, the staging table is not constant.&amp;nbsp; I have two customers who complete the information on the staging table at any given time.&amp;nbsp; So, I thought of requesting SAS to &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;automatically&lt;/STRONG&gt; &lt;/EM&gt;&lt;/U&gt;read the staging table and if it finds only one record (request) then SAS should extract the data and generate a report. If it finds two records (requests) then SAS should generate two distinct data sets for each row (request) and then generate a report for each record (request).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You didn't share sample code for report generation but the bit that creates table(s) based on what's in source variable Data1 is what the code I shared is doing - and which is basically the logic of the code you shared with some improvements.&lt;/P&gt;
&lt;P&gt;This code is data driven (automatic) so not really sure what's missing for you. Is the code you shared something you developed or was that just a copy/paste and you actually don't really understand what and how it generates code?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2024 08:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-data-from-a-data-source-given-more-data-sources/m-p/917881#M361570</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-26T08:55:22Z</dc:date>
    </item>
  </channel>
</rss>

