<?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: creating new variable and dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/836511#M36070</link>
    <description>Thank you!!</description>
    <pubDate>Mon, 03 Oct 2022 13:56:10 GMT</pubDate>
    <dc:creator>OJohn_StaT</dc:creator>
    <dc:date>2022-10-03T13:56:10Z</dc:date>
    <item>
      <title>creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823306#M35058</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;This is my dataset;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data Member_Data;
input VISIT_DATE :date9. MEMBER_ID $ VISIT_YEAR VISIT_STATUS;
format  VISIT_DATE :date9.;
datalines;
06NOV2013 AA10450Z 2013 0 
05JUN2014 AA10450Z 2014 1 
26JUN2014 AA10450Z 2014 1 
21AUG2014 AA10450Z 2014 1 
18SEP2014 AA10450Z 2014 1 
03DEC2014 AA10450Z 2014 1 
11MAR2015 AA10450Z 2015 1 
15APR2015 AA10450Z 2015 1 
07OCT2015 AA10450Z 2015 1 
13OCT2015 AA10450Z 2015 1 
26OCT2015 AA10450Z 2015 1 
09NOV2015 AA10450Z 2015 1 
07DEC2015 AA10450Z 2015 1 
21DEC2015 AA10450Z 2015 1 
19APR2017 AA10450Z 2017 1 
10SEP2018 AA10450Z 2018 0 
15APR2019 AA10450Z 2019 1 
;
run;



data Member_Data_New;
    set Member_Data;
    by member_id visit_year;
    delta_days=visit_date-lag(visit_date);
    if first.visit_year then do;
        delta_days=.;
        counter=0;
    end;
    counter+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OJohn_StaT_2-1657806169467.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73296i203F9FEBBB46F788/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OJohn_StaT_2-1657806169467.png" alt="OJohn_StaT_2-1657806169467.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I am trying to create a new variable for&lt;SPAN&gt;&amp;nbsp;total number of visit for each calendar&amp;nbsp;year.&amp;nbsp;Could you please help me for this issue because I am struggling. Here is a sample of the wanted dataset(below). Thank you for your time and your help in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OJohn_StaT_0-1657806103753.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73294i150401E113D9C7BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OJohn_StaT_0-1657806103753.png" alt="OJohn_StaT_0-1657806103753.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823306#M35058</guid>
      <dc:creator>OJohn_StaT</dc:creator>
      <dc:date>2022-07-14T13:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823318#M35062</link>
      <description>&lt;P&gt;You need to tell us the logic used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain in the final data set, how DELTA_DAYS and COUNTER and VISIT_STATUS is computed from the original data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain in the final data set, why 2013 and 2017 don't appear.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 14:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823318#M35062</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T14:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823339#M35065</link>
      <description>&lt;P&gt;Hello PaigeMiller,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time and help. Sorry there was a mistake and I fixed it. Here is my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data Member_Data;
input VISIT_DATE :date9. MEMBER_ID $ VISIT_YEAR VISIT_STATUS;
format  VISIT_DATE :date9.;
datalines;
06NOV2013 AA10450Z 2013 0 
05JUN2014 AA10450Z 2014 1 
26JUN2014 AA10450Z 2014 1 
21AUG2014 AA10450Z 2014 1 
18SEP2014 AA10450Z 2014 1 
03DEC2014 AA10450Z 2014 1 
11MAR2015 AA10450Z 2015 1 
15APR2015 AA10450Z 2015 1 
07OCT2015 AA10450Z 2015 1 
13OCT2015 AA10450Z 2015 1 
26OCT2015 AA10450Z 2015 1 
09NOV2015 AA10450Z 2015 1 
07DEC2015 AA10450Z 2015 1 
21DEC2015 AA10450Z 2015 1 
19APR2017 AA10450Z 2017 1 
10SEP2018 AA10450Z 2018 0 
15APR2019 AA10450Z 2019 1 
;
run;



data want;
    set Member_Data;
    by member_id visit_year;
    delta_days=visit_date-lag(visit_date);
    if first.visit_year then do;
        delta_days=.;
        counter=0;
    end;
    counter+1;
	do;
	if VISIT_STATUS=0 then counter=0;else counter=counter;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I created the following dataset using the above code;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OJohn_StaT_0-1657810796625.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73307iB80AC98C4084CF7C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OJohn_StaT_0-1657810796625.png" alt="OJohn_StaT_0-1657810796625.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set below is the data set I want to create;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OJohn_StaT_1-1657811016104.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73308iAF286DA7B0F30846/image-size/medium?v=v2&amp;amp;px=400" role="button" title="OJohn_StaT_1-1657811016104.png" alt="OJohn_StaT_1-1657811016104.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What I would like to find are those who visit at least once a year while showing symptoms of the disease. If anyone has visited while showing symptoms more than once during the year, then how many times did they visit in total and the difference in days between their first visit and their second visit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;delta_days=day difference between the current visit date and the previous visit date&lt;/P&gt;&lt;P&gt;Visit_status =showing symptoms of illness when visiting&lt;/P&gt;&lt;P&gt;counter=Calculation of the number of visits while showing symptoms of the disease in the same year&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 15:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823339#M35065</guid>
      <dc:creator>OJohn_StaT</dc:creator>
      <dc:date>2022-07-14T15:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823363#M35071</link>
      <description>&lt;P&gt;I think this still leaves some questions. I don't see the logic you are using to create the 2nd table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what you mean by "&lt;SPAN&gt;while showing symptoms", where is that in the input data set? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How do you get the final numbers for COUNTER in the output data set? What is the logic? What is the math?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 16:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823363#M35071</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T16:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823565#M35081</link>
      <description>&lt;P&gt;Hello PaigeMiller,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created second dataset by hand which means deleted some rows to show what I need to have as a final dataset. So Second dataset is what I want to create and I could not created the logic so that is why I asked for help.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;while showing symptoms=visit_status.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This data for doctor visit. Each row is the for each visit. Sometimes patient has&amp;nbsp;symptoms sometimes it does not have it. So if visit_status=1 then patient has&amp;nbsp;symptoms during the dr visit.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 18:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823565#M35081</guid>
      <dc:creator>OJohn_StaT</dc:creator>
      <dc:date>2022-07-15T18:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823623#M35084</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/143981"&gt;@OJohn_StaT&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello PaigeMiller,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created second dataset by hand which means deleted some rows to show what I need to have as a final dataset. So Second dataset is what I want to create and I could not created the logic so that is why I asked for help.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;while showing symptoms=visit_status.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This data for doctor visit. Each row is the for each visit. Sometimes patient has&amp;nbsp;symptoms sometimes it does not have it. So if visit_status=1 then patient has&amp;nbsp;symptoms during the dr visit.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You must know what you want, or you couldn't have created the 2nd data set. So, I am not asking for the logic to create the 2nd data set in SAS code, I am asking for you to describe the steps to create the 2nd data set in words. If you can't explain that logic in words, then code cannot be written. I still don't know how COUNTER in the 2nd data set is created from the original data.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2022 11:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823623#M35084</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-16T11:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823716#M35088</link>
      <description>&lt;P&gt;I think this is what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Member_Data;
input VISIT_DATE :date9. MEMBER_ID $ VISIT_YEAR VISIT_STATUS;
format  VISIT_DATE :date9.;
datalines;
06NOV2013 AA10450Z 2013 0 
05JUN2014 AA10450Z 2014 1 
26JUN2014 AA10450Z 2014 1 
21AUG2014 AA10450Z 2014 1 
18SEP2014 AA10450Z 2014 1 
03DEC2014 AA10450Z 2014 1 
11MAR2015 AA10450Z 2015 1 
15APR2015 AA10450Z 2015 1 
07OCT2015 AA10450Z 2015 1 
13OCT2015 AA10450Z 2015 1 
26OCT2015 AA10450Z 2015 1 
09NOV2015 AA10450Z 2015 1 
07DEC2015 AA10450Z 2015 1 
21DEC2015 AA10450Z 2015 1 
19APR2017 AA10450Z 2017 1 
10SEP2018 AA10450Z 2018 0 
15APR2019 AA10450Z 2019 1 
;
run;

*only keep records that had disease;
proc sort data=member_data out=member2;
    by member_id visit_date visit_year;
    where visit_status=1;
run;

data member3;
    set member2;
    by member_id  visit_year;
    format prev_visit date9.;
    retain prev_visit;
    if first.visit_year then do;
        counter=0;
        delta_days=.;
        prev_visit=visit_date;
    end;
    counter+1;
    *only keep first and second visits;
    if counter in (1,2);
    
    *calculate number of days between first and second visit;
    if counter=2 then do;
        delta_days=visit_date-prev_visit;
    end;
run;

proc sort data=member3;
    by member_id visit_year descending delta_days;
run;

*remove duplicates by year and member_id;
data member4;
    set member3;
    by member_id visit_year;
    if first.visit_year;
run;

*count # of visits in same year;
proc sql number;
    create table num_visits as 
    select member_id, visit_year, count(distinct visit_date) as visit_number
        from member2 
        group by member_id, visit_year;
quit;

proc sql;
    select m.member_id, m.visit_year, m.visit_status, m.counter, m.delta_days, n.visit_number
        from member4 as m
        join num_visits as n 
        on m.member_id=n.member_id and n.visit_year=m.visit_year
        order by m.member_id, m.visit_year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jul 2022 14:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823716#M35088</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-07-17T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823963#M35102</link>
      <description>&lt;P&gt;Thank you Tarhell13,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this is it. It work and I will try it with a bigger sample. I will let you now ASAP after I applied it.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 19:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823963#M35102</guid>
      <dc:creator>OJohn_StaT</dc:creator>
      <dc:date>2022-07-18T19:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823998#M35109</link>
      <description>&lt;P&gt;Okay, let me know if it works for you!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 22:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/823998#M35109</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-07-18T22:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable and dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/836511#M36070</link>
      <description>Thank you!!</description>
      <pubDate>Mon, 03 Oct 2022 13:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-new-variable-and-dataset/m-p/836511#M36070</guid>
      <dc:creator>OJohn_StaT</dc:creator>
      <dc:date>2022-10-03T13:56:10Z</dc:date>
    </item>
  </channel>
</rss>

