So the sorted visits look like
and the counting sequence I want is 1 1 1 1 2 2 2 2
Here is my failed attempt:
data endptx;
set endpt00;
by usubjid vst_num vsdat;
count=0;
if vst_num='A1' then count+1;
run;
I suspect that you want to reset the count to 0 when each USUBJID is encountered.
data endptx; set endpt00; by usubjid vst_num vsdat; if first.usubjid then count=0; if vst_num='A1' then count+1; run;
If that does not provide what you need then you will need to provide some example data for input and the expected output for the given example. Best is to provide the example data in the form of data step code.
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 </> icon or attached as text to show exactly what you have and that we can test code against.
I suspect that you want to reset the count to 0 when each USUBJID is encountered.
data endptx; set endpt00; by usubjid vst_num vsdat; if first.usubjid then count=0; if vst_num='A1' then count+1; run;
If that does not provide what you need then you will need to provide some example data for input and the expected output for the given example. Best is to provide the example data in the form of data step code.
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 </> icon or attached as text to show exactly what you have and that we can test code against.
What about:
data endptx;
set endpt00;
by usubjid vst_num vsdat;
if first.usubjid then count=0;
if vst_num='A1' then count+1;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.