BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10

Hi, 

I have problem with summarizing my data. I need to count how many distinct patient_Name for each distinct time point  if date_completed ne . 

I tried my code put I really missed up with it. 

I need you to suggest an edit to my code.  

proc sort data=readert1; by patient_name TimePoint; run;
data readert2;
set readert1;
by patient_name timepoint;
keep Patient_Name TimePoint Date_Completed ctime;
if date_completed ne . and first.Patient_name then do; ctime=0; end;
ctime+1;
if date_completed ne . and last.timepoint ;

this is the data that I need to summarize 

 

 Obs Patient_Name Timepoint Date_Completed1234567891011121314151617181920212223242526272829303132333435363738394041

W1490.1045001Baseline15DEC2017
W1490.1056002Baseline13NOV2017
W1490.1056002Baseline13NOV2017
W1490.1056002Week 1615NOV2017
W1490.1056002Week 1615NOV2017
W1490.1056002Week 2431JAN2018
W1490.1056002Week 2431JAN2018
W1490.1056002Week 815NOV2017
W1490.1056002Week 815NOV2017
W1490.1056003Baseline13NOV2017
W1490.1056003Week 813NOV2017
W1490.1056005Baseline13NOV2017
W1490.1056005Week 1613NOV2017
W1490.1056005Week 2425DEC2017
W1490.1056005Week 813NOV2017
W1490.1056006Baseline12DEC2017
W1490.1056006Week 1612DEC2017
W1490.1056006Week 2412JAN2018
W1490.1056006Week 812DEC2017
W1490.1068001Baseline13NOV2017
W1490.1068001Baseline13NOV2017
W1490.1068001Week 1613DEC2017
W1490.1068001Week 1613DEC2017
W1490.1068001Week 2425DEC2017
W1490.1068001Week 2425DEC2017
W1490.1068001Week 3222FEB2018
W1490.1068001Week 3222FEB2018
W1490.1068001Week 813NOV2017
W1490.1068001Week 813NOV2017
W1490.1068002Baseline.
W1490.1068002Week 8.
W1490.1089001Baseline15NOV2017
W1490.1089001Week 1615NOV2017
W1490.1089001Week 2418DEC2017
W1490.1089001Week 3210JAN2018
W1490.1089001Week 815NOV2017
W1490.1089002Baseline15DEC2017
W1490.1089003Baseline28DEC2017
W1490.1100002Baseline31JAN2018
W1490.1134001Baseline.
W1490.1134004Baseline30JAN2018
1 ACCEPTED SOLUTION

Accepted Solutions
mona4u
Lapis Lazuli | Level 10
I just found a way by using retain statement

View solution in original post

13 REPLIES 13
TomKari
Onyx | Level 15

Show us the code you've used so far, and maybe someone can suggest the necessary changes.

 

Tom

mona4u
Lapis Lazuli | Level 10
I just added the code
mona4u
Lapis Lazuli | Level 10

I need to do it in the data step 

ballardw
Super User

@mona4u wrote:

I need to do it in the data step 


Why? If a proc available to basically everyone works why the restriction.

 

You should show what the result for your example data would be. If you want to count names within timepoint then the sort and by processing likely should be BY Timepoint patient_name;

Perhaps something like this untested code.

proc sort data=readert1; 
   by timepoint patient_name ; 
run;
data readert2;
   set readert1 (where=(date_completed ne .));
   by timepoint patient_name ; 
   keep Patient_Name TimePoint Date_Completed ctime;
   if first.timepoint then patientcount=0;
   if first.patient then patientcount+1;
   if last.timepoint;
run;

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

mona4u
Lapis Lazuli | Level 10

this code doesn't summarize that data correctly 

ballardw
Super User

@mona4u wrote:

this code doesn't summarize that data correctly 


Since you did not show any desired result I don't think that is very responsive.

 

Show the correct summary for example data.

mona4u
Lapis Lazuli | Level 10

this code doesn't summarize that data correctly. 

appreciate your try

PaigeMiller
Diamond | Level 26
proc freq data=have(where=(date_completed^=.));
    tables patient_name/out=_a_;
run;

The number of observations in _a_ is the number of distinct patient_name exist in your data.

--
Paige Miller
mona4u
Lapis Lazuli | Level 10

that's not right I want the number of distinct patient_name for each distinct timepoint 

mona4u
Lapis Lazuli | Level 10
I just found a way by using retain statement
Reeza
Super User

The SUM statement implies RETAIN. 

 

 

ballardw
Super User

@mona4u wrote:
I just found a way by using retain statement

Show your actual working result code in the post you marked correct so that someone searching the forum for help can see the approach taken.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1186 views
  • 1 like
  • 5 in conversation