<?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 pass the dataset name in set statement from a variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604438#M175249</link>
    <description>&lt;P&gt;Yes, I&amp;nbsp;&lt;SPAN&gt;want all observations where id is missing in each of those three data sets&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Nov 2019 12:18:21 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2019-11-15T12:18:21Z</dc:date>
    <item>
      <title>How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604436#M175247</link>
      <description>&lt;P&gt;Assume I've a variable (Var_Name) which has the data as follows. Values of this variable is actually the dataset name. I'd like to know how can I pass that value as a dataset name in SET statement to test for missing values? Datasets Customer, company and Employee are in same structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Var_Name&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Customer&lt;/P&gt;
&lt;P&gt;Company&lt;/P&gt;
&lt;P&gt;Employee&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Operation which I want to&amp;nbsp; perform now is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output;
set &amp;lt;read value from Var_Name variable&amp;gt;; /*like set customer then set company followed by set employee */
if missing (id) then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 12:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604436#M175247</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-11-15T12:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604437#M175248</link>
      <description>&lt;P&gt;So you want all observations where id is missing in each of those three data sets?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 12:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604437#M175248</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-15T12:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604438#M175249</link>
      <description>&lt;P&gt;Yes, I&amp;nbsp;&lt;SPAN&gt;want all observations where id is missing in each of those three data sets&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 12:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604438#M175249</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-11-15T12:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604439#M175250</link>
      <description>&lt;P&gt;Try this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input Var_Name $;
datalines;
Customer
Company
Employee
;

data Customer;
id=.; var=1; 
run;

data Company;
id=1; var=1;  
run;

data Employee;
id=.; var=.; 
run;

data _null_;
    set one end=lr;
    if _N_=1 then call execute ('data want; set ');
    call execute(cat(Var_Name, '(where=(missing(id)))'));
    if lr then call execute(';run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id  var
.   1
.   .&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Nov 2019 12:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604439#M175250</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-15T12:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604442#M175251</link>
      <description>&lt;P&gt;Thank you. Any other way without using call execute?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 12:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604442#M175251</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-11-15T12:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604447#M175254</link>
      <description>&lt;P&gt;There are several ways to do this. Is there some way you prefer?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 12:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604447#M175254</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-15T12:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604478#M175261</link>
      <description>&lt;P&gt;Are the datasets compatible (have same, or at least not conflicting, structures)?&amp;nbsp; Sound like you want to run this program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT ;
  set Customer Company Employee ;
  where missing(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that would only work if the datasets are compatible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How long is the list datasets?&amp;nbsp; If the list is short enough you can just put it into a macro variable and use that in the SET statement above.&amp;nbsp;Where is the list of dataset names now?&amp;nbsp; If it is just in your head then just put it into a macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dslist= Customer Company Employee ;
....
data WANT ;
  set &amp;amp;dslist ;
  where missing(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the list of dataset names is in a dateset then you can put the list into a macro variable.&amp;nbsp; Do if it is in a dataset named DSLIST that has a variable named DSNAME then you can make the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select dsname into :dslist separated by ' ' from dslist;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Nov 2019 14:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604478#M175261</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-15T14:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass the dataset name in set statement from a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604586#M175298</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Compose a list of dsn names, then feed the macro variable containing it into SET with the INDSNAME= option. The value of the latter will indicate in the output data set to which original data sets the records belong:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data customer company employee ;                                                                                                        
  do id = 11, . , 12, 13 ; output customer ; end ;                                                                                      
  do id = 21, 22, 23, 24 ; output company  ; end ;                                                                                      
  do id = 31, . , 23, .  ; output employee ; end ;                                                                                      
  retain data1 1 data2 2 data3 3 ;                                                                                                      
run ;                                                                                                                                   
                                                                                                                                        
data dsn ;                                                                                                                              
  input dsn $32. ;                                                                                                                      
  cards ;                                                                                                                               
customer                                                                                                                                
company                                                                                                                                 
employee                                                                                                                                
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
proc sql noprint ;                                                                                                                      
  select dsn into :dsn separated by " " from dsn ;                                                                                      
quit ;                                                                                                                                  
                                                                                                                                        
data miss ;                                                                                                                             
  set &amp;amp;dsn indsname = dsn ;                                                                                                            
  where cmiss (id) ;                                                                                                                    
  DSNAME = dsn ;                                                                                                                          
run ;               
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 18:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-the-dataset-name-in-set-statement-from-a-variable/m-p/604586#M175298</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-15T18:58:10Z</dc:date>
    </item>
  </channel>
</rss>

