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;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.