<?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 Data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442144#M110587</link>
    <description>&lt;P&gt;Hi every one I wanted to know how do i find the new data entry of the week ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Example My data looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input :&amp;nbsp;&lt;/P&gt;&lt;P&gt;Week&amp;nbsp; &amp;nbsp;Patient&amp;nbsp;&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Week&amp;nbsp; Patient&amp;nbsp; &amp;nbsp;Flag&amp;nbsp;&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;New&amp;nbsp;&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;New&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically if i am finding the new patient in w6 then I have to look back all possible week and compare how many of these patients have visited me before W6 and if there a new which was not there till w6 then I have to mark that one as a new patient&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The weekly data set I have is huge I there is no way i can write individual subset code for everyone&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help will be much appreciated&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Mar 2018 10:26:04 GMT</pubDate>
    <dc:creator>spdattani</dc:creator>
    <dc:date>2018-03-04T10:26:04Z</dc:date>
    <item>
      <title>Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442144#M110587</link>
      <description>&lt;P&gt;Hi every one I wanted to know how do i find the new data entry of the week ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Example My data looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input :&amp;nbsp;&lt;/P&gt;&lt;P&gt;Week&amp;nbsp; &amp;nbsp;Patient&amp;nbsp;&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Week&amp;nbsp; Patient&amp;nbsp; &amp;nbsp;Flag&amp;nbsp;&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&lt;/P&gt;&lt;P&gt;W1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&amp;nbsp;&lt;/P&gt;&lt;P&gt;W2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;New&amp;nbsp;&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P4&lt;/P&gt;&lt;P&gt;W3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;New&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically if i am finding the new patient in w6 then I have to look back all possible week and compare how many of these patients have visited me before W6 and if there a new which was not there till w6 then I have to mark that one as a new patient&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The weekly data set I have is huge I there is no way i can write individual subset code for everyone&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help will be much appreciated&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 10:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442144#M110587</guid>
      <dc:creator>spdattani</dc:creator>
      <dc:date>2018-03-04T10:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442146#M110588</link>
      <description>&lt;P&gt;It looks like you have a second, unwritten rule here:&amp;nbsp; Don't mark anybody in W1 as "New".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the result you are asking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by patient week;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by patient week;&lt;/P&gt;
&lt;P&gt;if first.patient and week ne 'W1' then flag='New';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a hidden pitfall here.&amp;nbsp; This program assumes that the weeks go as high as 9, but no higher.&amp;nbsp; Otherwise the sorted order would be wrong:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;W1&lt;/P&gt;
&lt;P&gt;W10&lt;/P&gt;
&lt;P&gt;W11&lt;/P&gt;
&lt;P&gt;W2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have more than 9 weeks, you would need to extract a numeric variable from WEEK:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;weeknum = input( substr(week,2), 2.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use WEEKNUM instead of WEEK for sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 13:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442146#M110588</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-04T13:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442165#M110596</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Week   Patient) ($) ;
datalines;
W1          P1
W1          P2
W1          P3 
W2          P1   
W2          P2 
W2          P4
W3          P3
W3          P4
W3          P5
;
data want;
if _n_=1 then do;
if 0 then set have;
 dcl hash h();
 h.definekey('patient');
 h.definedone();
 end;
 set have end=last;
 by Week   Patient;
 length Flag $10;
 call missing(Flag);
 if first.week then _n+1;
if _n&amp;gt;1 then do; 
if h.check() ne 0 then Flag='NEW';
end;
h.replace();
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Mar 2018 19:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442165#M110596</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-04T19:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442166#M110597</link>
      <description>&lt;P&gt;Check this out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
infile datalines dlm=" ";
input Week $ Patient $;
datalines; 
W1 P1
W1 P2
W1 P3
W2 P1
W2 P2
W2 P4
W3 P3
W3 P4
W3 P5
;
run;

PROC SORT DATA=HAVE;
BY WEEK;
RUN;
%LET Patient_List=PATIENTS;
DATA WANT;
SET HAVE ;
IF FIND(SYMGET("Patient_List"),STRIP(PATIENT))=0 
		THEN DO;
			CALL SYMPUT("Patient_List",CATX(',',SYMGET("Patient_List"),PATIENT));
			FLAG="NEW";
		END;
IF WEEK="W1" THEN FLAG="";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Mar 2018 19:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442166#M110597</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-04T19:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442167#M110598</link>
      <description>&lt;P&gt;arrays:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Week   Patient) ($) ;
datalines;
W1          P1
W1          P2
W1          P3 
W2          P1   
W2          P2 
W2          P4
W3          P3
W3          P4
W3          P5
;

data want;
do _n_=1 by 1 until(eof);
set have end=eof;
by Week   Patient;
array temp(1000)$ _temporary_ ;/*arbitrary subscript value*/
length Flag $10;
call missing(Flag);
if first.week then _n+1;
if _n=1 then temp(_n_)=Patient;
else if _n&amp;gt;1 and patient not in temp then do; Flag="NEW";temp(_n_)=Patient;end;
output;
end;
drop _:;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Mar 2018 19:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442167#M110598</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-04T19:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442364#M110670</link>
      <description>&lt;P&gt;A quick follow-up here ... SAS provides a way that you can sort character values but make "W9" sort before "W10".&amp;nbsp; Here's the revised solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have sortseq=linguistic (numeric_collation=on);&lt;/P&gt;
&lt;P&gt;by patient week;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by patient;&lt;/P&gt;
&lt;P&gt;if first.patient and week ne 'W1' then flag='New';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the second BY statement has changed as well.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 14:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step/m-p/442364#M110670</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-05T14:20:13Z</dc:date>
    </item>
  </channel>
</rss>

