<?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: Data step help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639022#M190034</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322090"&gt;@mar0000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How would I create a variable that says 'Y' to every patient who has attempted to do something every 6 months?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Patient_ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Date.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Activity&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Football&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Basketball&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Ski&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07SEP2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Baseball&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the new variable to say "Y" for the 20FEB2020, 'N' for the second '20FEB2020' 25FEB2020, and 'Y' for 07SEP2020.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So it does not matter what the value of activity may be just that it is present? Is activity ever missing in this data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this could get you started, but missing value for the activity can mess with this.&lt;/P&gt;
&lt;PRE&gt;data have;
input Patient_ID $   date  Date9.     Activity $;
format date date9.;
datalines;
1234 20FEB2020 Football
1234 20FEB2020 Basketball
1234 25FEB2020 Ski
1234 07SEP2020 Baseball
;
data want;
   set have;
   by Patient_ID date;
   dd = intck('month',lag(date),date,'C');
   if first.Patient_ID then flag=1;
   else if dd &amp;lt; 6 then flag=0;
   else flag=1;
   drop dd;
run;
&lt;/PRE&gt;
&lt;P&gt;Note that the code is posted in a code box opened with the &amp;lt;/&amp;gt; icon to preserve formatting. Text pasted into the main message windows can have all sorts of odd things get removed or inserted. The data step shown is the way to provide data. Then there is no question about the types of variables involved. Dates, times and datetime values are especially sensitive. We sometimes spend lots of questions about "not working" code only to find out the "date" is not an actual SAS date value so the format or function attempted never had a chance of working correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW I would suggest coding the value as numeric 1 instead of 'Yes' and 0 instead of 'No'. It can be much easier to "count" things coded this way. Summing a variable gives you a number of Yes, the mean gives the percent of yes, Range tells if the value ever changed, max tells that at least one value was set and few other neat tricks depending on the type of questions asked.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Apr 2020 17:14:43 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-10T17:14:43Z</dc:date>
    <item>
      <title>Data step help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639013#M190030</link>
      <description>&lt;P&gt;How would I create a variable that says 'Y' to every patient who has attempted to do something every 6 months?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patient_ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Date.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Activity&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Football&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Basketball&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Ski&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07SEP2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Baseball&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the new variable to say "Y" for the 20FEB2020, 'N' for the second '20FEB2020' 25FEB2020, and 'Y' for 07SEP2020.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 16:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639013#M190030</guid>
      <dc:creator>mar0000</dc:creator>
      <dc:date>2020-04-10T16:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Data step help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639015#M190031</link>
      <description>Also, a 'N' for the 25FEB2020. Sorry, forgot to put that</description>
      <pubDate>Fri, 10 Apr 2020 16:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639015#M190031</guid>
      <dc:creator>mar0000</dc:creator>
      <dc:date>2020-04-10T16:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Data step help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639018#M190032</link>
      <description>&lt;P&gt;Every six months, starting when?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 17:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639018#M190032</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-10T17:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Data step help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639022#M190034</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322090"&gt;@mar0000&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How would I create a variable that says 'Y' to every patient who has attempted to do something every 6 months?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Patient_ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Date.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Activity&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Football&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Basketball&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25FEB2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Ski&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07SEP2020&amp;nbsp; &amp;nbsp; &amp;nbsp; Baseball&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the new variable to say "Y" for the 20FEB2020, 'N' for the second '20FEB2020' 25FEB2020, and 'Y' for 07SEP2020.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So it does not matter what the value of activity may be just that it is present? Is activity ever missing in this data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this could get you started, but missing value for the activity can mess with this.&lt;/P&gt;
&lt;PRE&gt;data have;
input Patient_ID $   date  Date9.     Activity $;
format date date9.;
datalines;
1234 20FEB2020 Football
1234 20FEB2020 Basketball
1234 25FEB2020 Ski
1234 07SEP2020 Baseball
;
data want;
   set have;
   by Patient_ID date;
   dd = intck('month',lag(date),date,'C');
   if first.Patient_ID then flag=1;
   else if dd &amp;lt; 6 then flag=0;
   else flag=1;
   drop dd;
run;
&lt;/PRE&gt;
&lt;P&gt;Note that the code is posted in a code box opened with the &amp;lt;/&amp;gt; icon to preserve formatting. Text pasted into the main message windows can have all sorts of odd things get removed or inserted. The data step shown is the way to provide data. Then there is no question about the types of variables involved. Dates, times and datetime values are especially sensitive. We sometimes spend lots of questions about "not working" code only to find out the "date" is not an actual SAS date value so the format or function attempted never had a chance of working correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW I would suggest coding the value as numeric 1 instead of 'Yes' and 0 instead of 'No'. It can be much easier to "count" things coded this way. Summing a variable gives you a number of Yes, the mean gives the percent of yes, Range tells if the value ever changed, max tells that at least one value was set and few other neat tricks depending on the type of questions asked.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 17:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-help/m-p/639022#M190034</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-10T17:14:43Z</dc:date>
    </item>
  </channel>
</rss>

