<?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 need to create variable Keeping data in a “one row for each visit” format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844529#M333879</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;1. Keeping data in a “one row for each visit” format (with multiple observations per patient) create a variable giving the number of months between the entry into the study for that subject and that study visit. (This will give the total number of months on study at each visit). PROC PRINT (e.g., the first 20 observations) a partial listing of the data to make sure that this new variable was created correctly.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this asking for the cumulative sum of months since last visit? If so, you can create a cumulative sum like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by patient_id;
    if first.patient_id then cumulative_sum=0;
    cumulative_sum+time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;can u share ur email id&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, you can't email it to me. You need to show us a portion of the data by typing it into your reply as working SAS data step code, or by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Other ways to provide the data are not acceptable. Pictures are not acceptable here. Excel files are not acceptable here. People tend to ignore this statement that other ways to provide the data are not acceptable, please don't ignore it. We're trying to help you, but you have to help us too. So get used to providing the data this way and do it EVERY SINGLE TIME from now on.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 23:03:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-11-15T23:03:00Z</dc:date>
    <item>
      <title>need to create variable Keeping data in a “one row for each visit” format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844518#M333872</link>
      <description>&lt;P&gt;Each follow-up visit is represented as one record in the data set. Variables in the file are:&lt;BR /&gt;1. Patient id (1-50)&lt;BR /&gt;2. Treatment group ( 0 = control group, and 1 = experimental group)&lt;BR /&gt;3. Visit number, numbered consecutively for each subject&lt;BR /&gt;4. Time since last visit (months, with 0 at the first visit)&lt;BR /&gt;5. Stage of disease (0 = early stage, and 1 = after disease progression)&lt;BR /&gt;All subjects are in the early stage of disease at the first visit. Subjects remain in the study after disease progression, so there may be several records from a study patient after disease progression. The data are sorted by study visit, and then by patient id within study visit. There are no missing data.&lt;BR /&gt;1. Keeping data in a “one row for each visit” format (with multiple observations per patient) create a variable giving the number of months between the entry into the study for that subject and that study visit. (This will give the total number of months on study at each visit). PROC PRINT (e.g., the first 20 observations) a partial listing of the data to make sure that this new variable was created correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i was trying to solve this question&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code I have used is as follows&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename in "E:\longdata.dat";&lt;BR /&gt;data temp;&lt;BR /&gt;infile in;&lt;BR /&gt;input pt_id trt_grp visits time stage ;&lt;BR /&gt;ttlmnth=time-visits;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i m not sure whether I have done it correctly or not because I havent understood the question properly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anyone help me out?&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30111"&gt;@Ric&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 22:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844518#M333872</guid>
      <dc:creator>pransh</dc:creator>
      <dc:date>2022-11-15T22:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: programming help needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844520#M333874</link>
      <description>&lt;P&gt;Have you examined your data to see if it appears as expected after reading? Proc print or open the data set in table view.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To work with &lt;STRONG&gt;subjects&lt;/STRONG&gt; by visit order you will need to sort the data by ID and visit number. (Proc sort).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in another data set you use the same BY variables as the sort. When you use a BY statement SAS provides automatic variables First. and Last. (the dots are important) with the variable name to indicate whether the current observation is the first or last of a by group. So by testing FIRST.Id variable you can set a counter to 0 or 1 (style choices). If the counter variable has been set as a RETAIN variable then the values will accumulate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without examples of the data we cannot tell if you have multiple visits per month, which means a simple counter won't work, or if there are gaps in the months which also means a simple counter will not work and you need to keep something else to calculate intervals with.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 22:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844520#M333874</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-15T22:32:30Z</dc:date>
    </item>
    <item>
      <title>Meaningful Subject Line Missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844521#M333875</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434867"&gt;@pransh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please go back to your original post and provide a subject line that describes the problem in some meaningful way. Since almost every question here could be "programming help needed", that's not meaningful. Put a brief description of the problem in the subject line, please.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 22:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844521#M333875</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-15T22:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Meaningful Subject Line Missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844523#M333876</link>
      <description>doone</description>
      <pubDate>Tue, 15 Nov 2022 22:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844523#M333876</guid>
      <dc:creator>pransh</dc:creator>
      <dc:date>2022-11-15T22:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: programming help needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844526#M333878</link>
      <description>in question it has been given that the data is already sorted by study visit, and then by patient id within study visit. There are no missing data.&lt;BR /&gt;&lt;BR /&gt;m not sure then why we will be using first. and last. thing&lt;BR /&gt;can u share ur email id , so that I can share a picture of dataset like how it looks so that it gives u a better idea</description>
      <pubDate>Tue, 15 Nov 2022 22:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844526#M333878</guid>
      <dc:creator>pransh</dc:creator>
      <dc:date>2022-11-15T22:53:08Z</dc:date>
    </item>
    <item>
      <title>need to create variable Keeping data in a “one row for each visit” format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844529#M333879</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;1. Keeping data in a “one row for each visit” format (with multiple observations per patient) create a variable giving the number of months between the entry into the study for that subject and that study visit. (This will give the total number of months on study at each visit). PROC PRINT (e.g., the first 20 observations) a partial listing of the data to make sure that this new variable was created correctly.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this asking for the cumulative sum of months since last visit? If so, you can create a cumulative sum like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by patient_id;
    if first.patient_id then cumulative_sum=0;
    cumulative_sum+time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;can u share ur email id&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, you can't email it to me. You need to show us a portion of the data by typing it into your reply as working SAS data step code, or by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Other ways to provide the data are not acceptable. Pictures are not acceptable here. Excel files are not acceptable here. People tend to ignore this statement that other ways to provide the data are not acceptable, please don't ignore it. We're trying to help you, but you have to help us too. So get used to providing the data this way and do it EVERY SINGLE TIME from now on.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 23:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844529#M333879</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-15T23:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: need to create variable Keeping data in a “one row for each visit” format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844665#M333928</link>
      <description>hi I did this but for next question&lt;BR /&gt;For a study like this, we want to report on the number of subjects in each group and how many total visits that there were per group. How many subjects and how many visits are there for each treatment group? (Hint: use PROC MEANS with two new created variables. The sum of 1s and 0s at the subject level is equal to the number of subjects. Also, what would the sum of 1s represent if the value, 1, is assigned for each observation?)&lt;BR /&gt;&lt;BR /&gt;i was having same output for number of visits and no of subjects&lt;BR /&gt;the code is as follow&lt;BR /&gt;data temp;&lt;BR /&gt;infile in;&lt;BR /&gt;input pt_id trt_grp visits time stage ;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data = temp;by pt_id;run;&lt;BR /&gt;data temp1;&lt;BR /&gt;set temp;&lt;BR /&gt;by pt_id;&lt;BR /&gt;if first.pt_id then totmnth=0;&lt;BR /&gt;totmnth+time;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=temp1;by trt_grp;run;&lt;BR /&gt;proc means data=temp1 noprint;&lt;BR /&gt;by trt_grp;&lt;BR /&gt;var pt_id visits;&lt;BR /&gt;output out=two n=total_pt total_visits;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;output : i am getting same number of subjects and visits for each trtr grp and I think that is wrong&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Nov 2022 17:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844665#M333928</guid>
      <dc:creator>pransh</dc:creator>
      <dc:date>2022-11-16T17:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: need to create variable Keeping data in a “one row for each visit” format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844667#M333929</link>
      <description>&lt;P&gt;WAG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile in;
input pt_id trt_grp visits time stage ;
run;

proc sort data = temp;
by pt_id;
run;


data temp1;
set temp;
by pt_id;
if first.pt_id then totmnth=1;&lt;BR /&gt;else totmnth=0;
run;

proc sort data=temp1;
by trt_grp;
run;

proc means data=temp1 noprint;
by trt_grp;
var totmnth visits;
output out=two sum(totmnth) = unique_patients n(visits) = num_visits;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depends on exactly how visits are coded.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To count unique per group each patients first record is marked as one and then all else are marked as 0. I think you're calling it totmnth from a previous question that was accumulating a variable but the usage here is different. And this assumes that the trt_grp does not change between pt_id which if true, this code could be simplified. You can sort by trt_grp and pt_id at once and then do the summary by pt_id and not have to resort saving at least one step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 17:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844667#M333929</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-16T17:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: need to create variable Keeping data in a “one row for each visit” format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844669#M333930</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;i did this still its giving me same for both patients and visits&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data temp;&lt;BR /&gt;infile in;&lt;BR /&gt;input pt_id trt_grp visits time stage ;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data = temp;by pt_id;run;&lt;BR /&gt;data temp1;&lt;BR /&gt;set temp;&lt;BR /&gt;by pt_id;&lt;BR /&gt;if first.pt_id then totmnth=0;&lt;BR /&gt;totmnth+time;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=temp1 (obs=20);run;&lt;BR /&gt;proc sort data=temp1;by trt_grp;run;&lt;BR /&gt;data temp1;&lt;BR /&gt;set temp;&lt;BR /&gt;by pt_id;&lt;BR /&gt;if first.pt_id then totmnth=0;&lt;BR /&gt;totmnth+time;&lt;BR /&gt;if first.pt_id then id=1;&lt;BR /&gt;else id=0;&lt;BR /&gt;run;&lt;BR /&gt;proc means data=temp1 noprint;&lt;BR /&gt;by trt_grp;&lt;BR /&gt;var id visits;&lt;BR /&gt;output out=two n=id total_visits;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for your reference I have pasted both the questions here&lt;BR /&gt;&lt;BR /&gt;1. Keeping data in a “one row for each visit” format (with multiple observations per patient) create a variable giving the number of months between the entry into the study for that subject and that study visit. (This will give the total number of months on study at each visit). PROC PRINT (e.g., the first 20 observations) a partial listing of the data to make sure that this new variable was created correctly.&lt;BR /&gt;2. For a study like this, we want to report on the number of subjects in each group and how many total visits that there were per group. How many subjects and how many visits are there for each treatment group? (Hint: use PROC MEANS with two new created variables. The sum of 1s and 0s at the subject level is equal to the number of subjects. Also, what would the sum of 1s represent if the value, 1, is assigned for each observation?)</description>
      <pubDate>Wed, 16 Nov 2022 17:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-to-create-variable-Keeping-data-in-a-one-row-for-each-visit/m-p/844669#M333930</guid>
      <dc:creator>pransh</dc:creator>
      <dc:date>2022-11-16T17:49:06Z</dc:date>
    </item>
  </channel>
</rss>

