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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.