<?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 write a code that can work when new data added to already data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330914#M74318</link>
    <description>&lt;P&gt;Please look at this:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=one;
   class aeb aed dos;
   table aeb*aed,
         (dos='' all='Total')*n='';
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 08 Feb 2017 17:05:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-02-08T17:05:44Z</dc:date>
    <item>
      <title>how to write a code that can work when new data added to already data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330696#M74244</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;&lt;P&gt;I need help &amp;nbsp;in making my code robust.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running several data steps to create a dataset for my table. My code is working fine for the data one. But everymonth new data will be added to this data with different aeb and aed variable values but dos variable values remain same. So I have to make changes. Is there way to write the code to work even when new data added&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For my table I am counting number of distinct ID by dos,aeb,aed. The total variable values should only come from dos 17 and 30&lt;/P&gt;&lt;P&gt;Please help. Thank you very much for the great support&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input id aeb $ aed $ dos $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 inf nap 17&lt;BR /&gt;2 inf nap 17&lt;BR /&gt;3 inf nap 30&lt;BR /&gt;4 inf nap 30&lt;BR /&gt;5 inf nap 30&lt;BR /&gt;6 gei pai 30&lt;BR /&gt;7 gei pai place&lt;BR /&gt;8 inf nap place&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output &amp;nbsp;needed to create my table&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;aeb &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; aed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17 &amp;nbsp; &amp;nbsp;30 &amp;nbsp; &amp;nbsp; Place &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Total&lt;BR /&gt;inf &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;nsp &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;BR /&gt;gei &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pai &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;P&gt;data dos;&lt;BR /&gt;set one(where=(dos in '17' '30'));&lt;BR /&gt;output;&lt;BR /&gt;trta="TOTAL";&lt;BR /&gt;output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data place;&lt;BR /&gt;set one(where=(dos='place'));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table t1 as&lt;BR /&gt;select count(id) as NS,dos,aeb,aed&lt;BR /&gt;from dos&lt;BR /&gt;group by dos,aeb,aed;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table t2 as&lt;BR /&gt;select count(id) as NS,dos,aeb,aed&lt;BR /&gt;from place&lt;BR /&gt;group by dos,aeb,aed;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ifndatafromt1 gadatafromt1;&lt;BR /&gt;set t1;&lt;BR /&gt;if aeb='ifn' then output ifndatafromt1;&lt;BR /&gt;if aeb='gei' then output gadatafromt1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data ifnfromt2 gafromt2;&lt;BR /&gt;set t2;&lt;BR /&gt;if aeb='ifn' then output ifnfromt2;&lt;BR /&gt;if aeb='gei' then output gafromt2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data ifnfromt1t2(data from t1 and t2);&lt;BR /&gt;set ifndatafromt1 ifnfromt2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=ifnfromt1t2 out=trandata;&lt;BR /&gt;id dos;&lt;BR /&gt;var ns;&lt;BR /&gt;COPY aeb aed;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 02:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330696#M74244</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-02-08T02:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a code that can work when new data added to already data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330702#M74249</link>
      <description>&lt;P&gt;I'd approach the problem slightly differently:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
  input id aeb $ aed $ dos $;
datalines;
1 inf nap 17
2 inf nap 17
3 inf nap 30
4 inf nap 30
5 inf nap 30
6 gei pai 30
7 gei pai place
8 inf nap place
;

proc sort data=one;
  by  descending aeb aed dos;
run;

proc freq data=one;
  by aeb aed notsorted;
  tables dos/out=want (drop=percent);
run;

proc transpose data=want out=want (drop=_name_ _label_);
  by aeb aed notsorted;
  var count;
  id dos;
run;

data want;
  set want;
  array data _17 _30 Place;
  do over data;
    if missing(data) then data=0;
  end;
  total=_17+_30;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 03:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330702#M74249</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-08T03:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a code that can work when new data added to already data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330703#M74250</link>
      <description>&lt;P&gt;Look at PROC REPORT or TABULATE. Or FREQ.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need a data set or a report?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pick one, try it and post back with issues.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 03:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330703#M74250</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-08T03:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a code that can work when new data added to already data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330713#M74255</link>
      <description>&lt;P&gt;Thank you very much. That was great&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is your proc freq exactly gets the counts as &amp;nbsp;my proc sql code. I am suppose to get distinct id count by dos,aeb,aed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help. Thank you very much&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your code:&lt;/P&gt;&lt;PRE&gt;proc freq data=one;
  by aeb aed notsorted;
  tables dos/out=want (drop=percent);
run;&lt;/PRE&gt;&lt;P&gt;my sql code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create table t1 as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select count( distinct id) as NS,dos,aeb,aed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*Sorry In my SQL code I forgot to put (distinct) before*\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from dos&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;group by dos,aeb,aed;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 05:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330713#M74255</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2017-02-08T05:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a code that can work when new data added to already data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330866#M74298</link>
      <description>&lt;P&gt;No. Proc freq, by itself, won't provide unduplicated counts. Of course, you could force it by adding a proc sort nodupkey before proc freq. i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
  input id aeb $ aed $ dos $;
  datalines;
1 inf nap 17
1 inf nap 17
2 inf nap 17
3 inf nap 30
4 inf nap 30
5 inf nap 30
6 gei pai 30
7 gei pai place
8 inf nap place
;
proc sort data=one nodupkey;
  by dos aeb aed id;
run;

proc sort data=one;
  by  descending aeb aed dos;
run;

proc freq data=one;
  by aeb aed notsorted;
  tables dos/out=want (drop=percent);
run;

proc transpose data=want out=want (drop=_name_ _label_);
  by aeb aed notsorted;
  var count;
  id dos;
run;

data want;
  set want;
  array data _17 _30 Place;
  do over data;
    if missing(data) then data=0;
  end;
  total=_17+_30;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 15:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330866#M74298</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-08T15:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a code that can work when new data added to already data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330914#M74318</link>
      <description>&lt;P&gt;Please look at this:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=one;
   class aeb aed dos;
   table aeb*aed,
         (dos='' all='Total')*n='';
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2017 17:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-code-that-can-work-when-new-data-added-to-already/m-p/330914#M74318</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-08T17:05:44Z</dc:date>
    </item>
  </channel>
</rss>

