Each follow-up visit is represented as one record in the data set. Variables in the file are:
1. Patient id (1-50)
2. Treatment group ( 0 = control group, and 1 = experimental group)
3. Visit number, numbered consecutively for each subject
4. Time since last visit (months, with 0 at the first visit)
5. Stage of disease (0 = early stage, and 1 = after disease progression)
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.
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.
i was trying to solve this question
the code I have used is as follows
filename in "E:\longdata.dat";
data temp;
infile in;
input pt_id trt_grp visits time stage ;
ttlmnth=time-visits;
run;
i m not sure whether I have done it correctly or not because I havent understood the question properly
can anyone help me out? @ballardw @PaigeMiller @Ric
Have you examined your data to see if it appears as expected after reading? Proc print or open the data set in table view.
To work with subjects by visit order you will need to sort the data by ID and visit number. (Proc sort).
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.
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.
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.
Is this asking for the cumulative sum of months since last visit? If so, you can create a cumulative sum like this:
data want;
set have;
by patient_id;
if first.patient_id then cumulative_sum=0;
cumulative_sum+time;
run;
can u share ur email id
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 these instructions. 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.
WAG
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;
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;
Depends on exactly how visits are coded.
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.
Hello @pransh
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.