<?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 do I keep a data element created inside a macro, so I can work on it, after the macro execut in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539260#M148559</link>
    <description>&lt;P&gt;It's easiest to accumulate them at this point:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=test;                                                 
  run;                                                                  
  title "";   

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just add to the program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append data=test base=all_tests;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first time through, when ALL_TESTS doesn't yet exist, this creates ALL_TESTS by copying TEST.&amp;nbsp; All the subsequent times through, it appends TEST to the end of ALL_TESTS.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Feb 2019 12:09:32 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-28T12:09:32Z</dc:date>
    <item>
      <title>How do I keep a data element created inside a macro, so I can work on it, after the macro execution?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539259#M148558</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a newbie in SAS-programming, but have coded in many mainframe language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made a SAS-program, running under z/OS, that takes a list of files and runs them through a set of macros, to retrieve membernames and data about each member from the file, one file at the time. (PDS-files).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Inside the innermost macro, a data-element test is created, that contains all the information about the members found in a single dataset. I can print the dataset from each file, to see what it contains.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My challenge is to sum the test datasets from the innermost macro, and keep them in a data element, after all files have been processed, so that I can continue working on the complete member-list outside the outermost macro.&amp;nbsp;In the original example the data element created a print-file for each element in the filelist, but I need a file containing ALL members from ALL the files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone advise me of how to obtain my goal ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most of the core of the code below has been retrieved from&lt;A href="https://documentation.sas.com/?docsetId=hosto390&amp;amp;docsetTarget=n0zi363n2s7wx4n16wm24jagfnvh.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt; "SAS 9.4 Companion for z/OS, Sixth edition, SOURCE Procedure: z/OS, example 3: Producing Directory Records."&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards Henrik.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  *****************************;                                          
  * filenames to be processed *;                                         
  *****************************;                                          
  data filenames;                                                       
    format level $2.;                                                   
    format file_type $8.;                                                    
    format name_of_file $35.;                                                
    INPUT                                                               
          level   $                                                     
          name_of_file $                                                     
          file_type    $;                                                    
 datalines;                                                             
 1 user.test.pli PLI                                               
 2 common.prod.pli PLI                                                
 1 user.test.cobol cobol                                               
 2 common.prod.cobol cobol
 ;                                                                      
 
*-------------------------------------------------------------------*;  
 proc sort data=filenames;                                              
   by file_type level name_of_file;                                               
 run;                                                                   
*-------------------------------------------------------------------*;  
 proc print data=filenames;                                             
 run;                                                                   
*-------------------------------------------------------------------*;  
%MACRO OBSN(ds,nobsp);                                                  
  %global dset nobs;                                                    
  %let dset=&amp;amp;ds;                                                        
  %let dsid = %sysfunc(open(&amp;amp;dset));                                    
  %if &amp;amp;dsid %then                                                       
  %do;                                                                  
    %let nobs =%sysfunc(attrn(&amp;amp;dsid,NOBS));                             
    %let rc = %sysfunc(close(&amp;amp;dsid));                                   
  %end;                                                                 
  %else                                                                 
    %put Open for data set &amp;amp;dset failed - %sysfunc(sysmsg());           
%MEND OBSN;                                                             
*-------------------------------------------------------------------*;  
%macro find_members(f_level,f_name_of_file,f_file_type);                          
  %let i_level = &amp;amp;f_level;                                              
  %let i_name_of_file = &amp;amp;f_name_of_file;                                          
  %let i_file_type = &amp;amp;f_file_type;                                                
 
  FILENAME COBUSER  "&amp;amp;i_name_of_file" DISP=SHR;                              
  *--------------------------------------*;                             
  filename dirent '&amp;amp;temp';                                              
                                                                        
  proc source indd=cobuser nodata noprint dirdd=dirent;                 
                                                                        
  data   test;                                                          
                                                                        
  infile dirent eof=EXIT;                                               
*  file print header=HDR*;                                              
  retain TotEntries 0;                                                  
                                                                        
  input  member $8. ttr pib3.  ind pib1. @;                             
  TotEntries = ( TotEntries + 1);                                       
  halfwords = mod(ind,32);                                              
                                                                        
  if (halfwords = 15) or (halfwords = 20)                               
  then do;                                                              
    input ver      pib1.    /*  1    Version               */           
          mod      pib1.    /*  2    Modification          */           
          flags    pib1.    /*  3    Flags                 */           
          modifids pib1.    /*  4    Seconds last modified */           
          ccreate  pib1.    /*  5    Creation Date         */           
          create   pd3.     /*  6-8  "           "         */           
          cchanged pib1.    /*  9-9  Last Modified Date    */           
          changed  pd3.     /* 10-12 "           "         */           
          hh       pk1.     /* 13    Hour                  */           
          mm       pk1.     /* 14    Minute                */           
          ccurrent pib2.    /* 15-16 Current Lines         */           
          cinitial pib2.    /* 17-18 Initial Lines         */           
          cmodifid pib2.    /* 19 20 Modified Lines        */           
          userid   $char7.  /* 21-27 Userid                */           
          depends  $char1.  /* 28    If bit 3/byte 3 = ON  */           
          Ecurrent pib4.    /* 29-32 ON:  Current Lines    */           
          Einitial pib4.    /* 33-36 ON:  Initial Lines    */           
          Emodifid pib4. ;  /* 37-40 ON:  Modified Lines   */           
                                                                        
    yyyydddc = (ccreate * 100000)  + 1900000 + create;                  
    jcreate  = datejul(yyyydddc);                                       
    yyyydddx = (cchanged * 100000) + 1900000 + changed;;                
    jchange  = datejul(yyyydddx);                                       
                                                                        
    s_lvl = symget("i_level");                                          
    s_sprog =  symget("i_file_type");                                   
    s_path =  symget("i_name_of_file");                                 
                                                                        
  end;                                                                  
                                                                        
  return;                                                               
                                                                        
  EXIT:                                                                 
    put "Directory Entries Processed: " TotEntries;                     
                                                                        
  title "Print of TEST after &amp;amp;i_name_of_file";                          
  proc print data=test;                                                 
  run;                                                                  
  title "";                                                             
                                                                        
%mend find_members;                                                     
*-------------------------------------------------------------------*;  
%MACRO get_data(Navn,Nr);                                              
  put ### get_data : Processing &amp;amp;navn &amp;amp;nr;                          
  %GLOBAL HJ_level;                                                 
  %GLOBAL HJ_name_of_file;                                          
  %GLOBAL HJ_file_type;                                             
  data _null_;                                                      
    set &amp;amp;navn;                                                      
    if _n_ = &amp;amp;nr                                                    
    then do;                                                        
      call symput("hj_level",level);                                
      call symput("hj_name_of_file",name_of_file);                  
      call symput("hj_file_type",file_type);                        
    end;                                                            
  run;                                                              
  %put ### get_data : End of processing;                                      
%MEND get_data;                                                     
*-------------------------------------------------------------------*;  
%macro start(idata);                                                    
  %put ### START 001;                                                   
  %obsn(&amp;amp;idata,NOBS);                                                   
  %let ant = &amp;amp;NOBS;                                                     
  %PUT Antal = &amp;amp;ant;                                                    
  %do i = 1 %to &amp;amp;ant;                                                   
    %get_data(&amp;amp;idata,&amp;amp;i);                                              
    %let x_level   = &amp;amp;hj_level;                                         
    %let x_name_of_file = &amp;amp;hj_name_of_file;                             
    %let x_file_type    = &amp;amp;hj_file_type;                                
    %find_members(&amp;amp;hj_level, &amp;amp;hj_name_of_file, &amp;amp;hj_file_type);          
  %end; 
  %put ### START 999;                                                   
%mend;                                                                  
*-------------------------------------------------------------------*;  
data _null_;                                                            
  set filenames;                                                        
  options mprint;                                                       
  %start(filenames);                                                    
run;                                                                    &lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Feb 2019 12:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539259#M148558</guid>
      <dc:creator>uob_top</dc:creator>
      <dc:date>2019-02-28T12:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I keep a data element created inside a macro, so I can work on it, after the macro execut</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539260#M148559</link>
      <description>&lt;P&gt;It's easiest to accumulate them at this point:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=test;                                                 
  run;                                                                  
  title "";   

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just add to the program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append data=test base=all_tests;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first time through, when ALL_TESTS doesn't yet exist, this creates ALL_TESTS by copying TEST.&amp;nbsp; All the subsequent times through, it appends TEST to the end of ALL_TESTS.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 12:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539260#M148559</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-28T12:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I keep a data element created inside a macro, so I can work on it, after the macro execut</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539368#M148601</link>
      <description>&lt;P&gt;You seem to have made using data to drive calling a macro much too complicated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;                                                      
    set &amp;amp;navn;                                                      
    call execute(cats(
      '%nrstr(%find_members)(',level,',',name_of_file,',',file_type,')'
    ));          
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Feb 2019 16:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-keep-a-data-element-created-inside-a-macro-so-I-can/m-p/539368#M148601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-28T16:34:36Z</dc:date>
    </item>
  </channel>
</rss>

