<?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: Run same procedure over multiple datasets and merge the results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884490#M349437</link>
    <description>&lt;P&gt;Please show your proc means code as an example.&lt;/P&gt;
&lt;P&gt;Your requirement of "only have the all unique ID and % " asks for something related to variable(?) named Id but is not described in your proc means or elsewhere in the description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which means that "unique ID and %" brings up a very significant question of what is the denominator to be used in the %? The occurences of ID across all the data sets? Within each data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of small data sets as an example of input and the relatively easy to calculate by hand to show the example output for those would go a long way to clarification.&lt;/P&gt;
&lt;P&gt;Here is an example of how to share data or provide examples with data step code:&lt;/P&gt;
&lt;PRE&gt;data d1;
  input id $  test_result;
datalines;
1   1
1   0
2   1
2   1
2   0
3   0
;
data d2;
  input id $  test_result;
datalines;
1   0
2   1
2   1
2   1
;
data d3;
  input id $  test_result;
datalines;
1   1
1   1
2   0
2   0
2   0
3   1
;&lt;/PRE&gt;
&lt;P&gt;Pasting the code into a text box opened on the forum with the &amp;lt;/&amp;gt; icon above the message window sets it apart from general question text.&lt;/P&gt;
&lt;P&gt;Note the above example specifically includes at least one Id not in each set. The example is small enough that you should be able to calculate whatever your result is by hand and show that, also best as data step code similar to shown.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data is significantly different in behavior than that shown you now have a pattern on how to provide such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2023 14:53:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-07-12T14:53:16Z</dc:date>
    <item>
      <title>Run same procedure over multiple datasets and merge the results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884420#M349398</link>
      <description>&lt;P&gt;Hi everyone!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have about 93 individual datasets. &amp;nbsp;All these datasets have same column names. For each dataset, I will calculate a % based on one column "test_result". &amp;nbsp;The test result is coded as 1 (pass) and 0 (fail).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use proc means sum to count total tests and number of pass and eventually get a % of the pass and output the % in a new dataset with a unique ID (linked back to the original dataset).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to run the same procedure for the 93 datasets, and make a new dataset to only have the all unique ID and % in.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not familiar with macro and tried a few but did not seem work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any helps are appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 01:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884420#M349398</guid>
      <dc:creator>cindyf</dc:creator>
      <dc:date>2023-07-12T01:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Run same procedure over multiple datasets and merge the results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884421#M349399</link>
      <description>&lt;P&gt;Use dictionary dataset and I/O function, you can do it in an easy way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Generate datasets for test;
data have1 have2;
  call streaminit(42);
  do i=1 to 42;
    test_result=rand('binomial',0.5,1);
    output have1;
  end;
  do i=1 to 6174;
    test_result=rand('binomial',0.5,1);
    output have2;
  end;
run;

*Get count of 'test_result=1' with the help of dictionary dataset and I/O function;
data want;
  set sashelp.vtable;
  where libname='WORK' and memtype='DATA' and memname like 'HAVE%';

  did=open(catx('.',libname,memname)||'(where=(test_result=1))');
  if did then do;
    nobs_1=attrn(did,'nlobsf');
    did=close(did);
  end;
  percent=nobs_1/nlobs*100;

  format percent 8.2;
  keep libname memname memlabel nlobs nobs_1 percent;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jul 2023 02:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884421#M349399</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-07-12T02:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Run same procedure over multiple datasets and merge the results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884423#M349400</link>
      <description>&lt;P&gt;If you are not familiar with dictionary dataset and I/O function, you can use proc freq to make it, too.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mid1;
  set have:(keep=test_result) indsname=indsname;
  dsname=indsname;
run;

proc freq data=mid1 noprint;
  tables test_result*dsname/out=want(where=(test_result=1) keep=dsname test_result pct_col) outpct;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, you can check the dataset work.want.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 02:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884423#M349400</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-07-12T02:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Run same procedure over multiple datasets and merge the results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884442#M349411</link>
      <description>&lt;P&gt;Create a DATA step view to concatenate all datasets, and use the INDSNAME= option to create a variable containing the dataset name. Then run your analysis BY this new variable in a single step.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 07:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884442#M349411</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-12T07:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Run same procedure over multiple datasets and merge the results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884490#M349437</link>
      <description>&lt;P&gt;Please show your proc means code as an example.&lt;/P&gt;
&lt;P&gt;Your requirement of "only have the all unique ID and % " asks for something related to variable(?) named Id but is not described in your proc means or elsewhere in the description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which means that "unique ID and %" brings up a very significant question of what is the denominator to be used in the %? The occurences of ID across all the data sets? Within each data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A couple of small data sets as an example of input and the relatively easy to calculate by hand to show the example output for those would go a long way to clarification.&lt;/P&gt;
&lt;P&gt;Here is an example of how to share data or provide examples with data step code:&lt;/P&gt;
&lt;PRE&gt;data d1;
  input id $  test_result;
datalines;
1   1
1   0
2   1
2   1
2   0
3   0
;
data d2;
  input id $  test_result;
datalines;
1   0
2   1
2   1
2   1
;
data d3;
  input id $  test_result;
datalines;
1   1
1   1
2   0
2   0
2   0
3   1
;&lt;/PRE&gt;
&lt;P&gt;Pasting the code into a text box opened on the forum with the &amp;lt;/&amp;gt; icon above the message window sets it apart from general question text.&lt;/P&gt;
&lt;P&gt;Note the above example specifically includes at least one Id not in each set. The example is small enough that you should be able to calculate whatever your result is by hand and show that, also best as data step code similar to shown.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data is significantly different in behavior than that shown you now have a pattern on how to provide such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 14:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884490#M349437</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-12T14:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Run same procedure over multiple datasets and merge the results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884492#M349438</link>
      <description>It's easier to combine all datasets into one, adding in a variable that will uniquely identify each dataset and then do the calculation using the BY/CLASS feature of PROC MEANS.</description>
      <pubDate>Wed, 12 Jul 2023 15:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-same-procedure-over-multiple-datasets-and-merge-the-results/m-p/884492#M349438</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-12T15:00:24Z</dc:date>
    </item>
  </channel>
</rss>

