<?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 Loop through datasets and variables in source file in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500491#M353</link>
    <description>&lt;DIV&gt;Source File:&lt;/DIV&gt;&lt;DIV&gt;Dataset&amp;nbsp; &amp;nbsp; Variable_List&lt;/DIV&gt;&lt;DIV&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var1_A&lt;/DIV&gt;&lt;DIV&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var2_A&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var1_B&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var2_B&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3_B&lt;/DIV&gt;&lt;DIV&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3_c&lt;/DIV&gt;&lt;DIV&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var4_C&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Source file has above two columns.Before I start processing the data,I want to check if&amp;nbsp; variables in Dataset A and B have any missing values. If they are present then I want report them to a dataset:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;say for example, Var2_A and Var3_B ,Var4_C&amp;nbsp; has a missing values&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Data_Report table:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Dataset&amp;nbsp; &amp;nbsp; Variable_miss&lt;/DIV&gt;&lt;DIV&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var2_A&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3_B&lt;/DIV&gt;&lt;DIV&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var4_C&lt;/DIV&gt;</description>
    <pubDate>Mon, 01 Oct 2018 17:50:14 GMT</pubDate>
    <dc:creator>SASPhile</dc:creator>
    <dc:date>2018-10-01T17:50:14Z</dc:date>
    <item>
      <title>Loop through datasets and variables in source file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500491#M353</link>
      <description>&lt;DIV&gt;Source File:&lt;/DIV&gt;&lt;DIV&gt;Dataset&amp;nbsp; &amp;nbsp; Variable_List&lt;/DIV&gt;&lt;DIV&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var1_A&lt;/DIV&gt;&lt;DIV&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var2_A&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var1_B&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var2_B&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3_B&lt;/DIV&gt;&lt;DIV&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3_c&lt;/DIV&gt;&lt;DIV&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var4_C&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Source file has above two columns.Before I start processing the data,I want to check if&amp;nbsp; variables in Dataset A and B have any missing values. If they are present then I want report them to a dataset:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;say for example, Var2_A and Var3_B ,Var4_C&amp;nbsp; has a missing values&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Data_Report table:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Dataset&amp;nbsp; &amp;nbsp; Variable_miss&lt;/DIV&gt;&lt;DIV&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var2_A&lt;/DIV&gt;&lt;DIV&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var3_B&lt;/DIV&gt;&lt;DIV&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var4_C&lt;/DIV&gt;</description>
      <pubDate>Mon, 01 Oct 2018 17:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500491#M353</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2018-10-01T17:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through datasets and variables in source file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500655#M383</link>
      <description>&lt;P&gt;Sorry&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;, but I cannot understand the logic of the processing you requested..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Where are there missing values in the "source file"?&lt;/LI&gt;
&lt;LI&gt;And if you want "Var2_A" because there's a "Var2" in B and/or C, and you want "Var3_B" because there's a Var3 in A and/or C, but why do you want "Var4_C" if there's no "Var4" in A and/or B?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yours in confusion,&lt;/P&gt;
&lt;P&gt;Andrew.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 09:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500655#M383</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2018-10-02T09:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through datasets and variables in source file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500686#M384</link>
      <description>&lt;P&gt;Here is an approach that works regardless of the type of variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sample data sets */
data A;
Var1_A=1;Var2_A=1;output;
Var1_A=1;Var2_A=.;output;
run;
data B;
Var1_B="a";Var2_B="a";Var3_B="a";output;
Var1_B="a";Var2_B="a";Var3_B="";output;
run;
data C;
Var3_C=1;output;
Var4_C=.;output;
run;

/* Source data set */
data Source;
input Dataset $ Variable_List $;
datalines;
A Var1_A
A Var2_A
B Var1_B
B Var2_B
B Var3_B
C Var3_C
C Var4_C
;

data want;
   length Dataset $20 Variable_miss $20;
   if 0 then set A B C;
   set Source(rename=(Variable_List=Variable_miss));

   declare hash h(dataset:dataset, multidata:"Y", ordered:"A");
   h.definekey(Variable_miss);
   h.definedone();
   declare hiter hi("h");

   hi.first();

   if strip(vvaluex(Variable_miss)) in ("",".") then output;
   keep dataset Variable_miss;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;, I'm curious if this met your needs? Regards.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2018 10:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500686#M384</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-07T10:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through datasets and variables in source file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500695#M385</link>
      <description>&lt;P&gt;Program&amp;nbsp; below would be helpful in consolidating the variables that has got only missing values across the library&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table tblscn as select memname, libname from dictionary.tables where libname='TMP';
quit;

%macro loop;
%local num i mv_memname mv_libname;
%let dsid = %sysfunc(open(work.tblscn));
%let num = %sysfunc(attrn(&amp;amp;dsid,nlobs));
%let rc = %sysfunc(close(&amp;amp;dsid));

%do i=1 %to &amp;amp;num;
data _null_;
p = &amp;amp;i;
set work.tblscn point=p;
call symputx('mv_memname',memname);
call symputx('mv_libname',libname);
stop;
run;
data _null_;
set &amp;amp;mv_libname..&amp;amp;mv_memname. end=last; 
array _a{*} $ _character_;
array _b{*} _numeric_;
length varname memname libname $32;
if _n_ = 1 then do;
call missing(var, varn, varname, memname, libname);
declare hash nmc (ordered:"a");
nmc.definekey("var");
nmc.definedata('var','varname','memname','libname');
nmc.definedone();
declare hiter iter('nmc');
do var=1 to dim(_a);
nmc.add(key:var,data:var,data:vname(_a[var]),data:"&amp;amp;memname.",data:"&amp;amp;libname.");
put _all_;
end;
declare hash nmn (ordered:"a");
nmn.definekey("varn");
nmn.definedata('varn','varname','memname','libname');
nmn.definedone();
declare hiter niter('nmn');
do varn=1 to dim(_b);
nmn.add(key:varn,data:varn,data:vname(_b[varn]),data:"&amp;amp;memname.",data:"&amp;amp;libname.");
put _all_;
end;
end; 
rc=iter.first();
do while (rc = 0);
if _a[var] ne '' then do; 
_x=var;
rc=iter.next();
nmc.remove(key:_x);
end;
else rc=iter.next();
end;
rc=niter.first();
do while (rc = 0);
if _b[varn] ne . then do; 
_y=varn;
rc=niter.next();
nmn.remove(key:_y);
end;
else rc=niter.next();
end; 
if last then do;
nmc.output(dataset:'mc_ds');
nmn.output(dataset:'mcn_ds');
end;
run;
proc append base=mc_ds data=mcn_ds(rename=varn=var) force; run;
proc append base=all_missing_var data=mc_ds force; run;
%end;
%mend loop;
%loop;&lt;/CODE&gt;&lt;/PRE&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>Tue, 02 Oct 2018 11:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/500695#M385</guid>
      <dc:creator>saivenkat</dc:creator>
      <dc:date>2018-10-02T11:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through datasets and variables in source file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/510991#M2071</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp; , I'm curious if this code met your needs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 09:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/510991#M2071</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-07T09:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through datasets and variables in source file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/511426#M2164</link>
      <description>&lt;P&gt;There are more updates on the enahanement are coming.I havent tested it yet, will let you know if it worked. Thanks for your followup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 16:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Loop-through-datasets-and-variables-in-source-file/m-p/511426#M2164</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2018-11-08T16:12:43Z</dc:date>
    </item>
  </channel>
</rss>

