BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jenim514
Pyrite | Level 9

Hi all!

I have a counting visit question 🙂  For ONE subject, if I had visits A1 A3 D1 LD  and again A1 A2 A3 D1  (all on different dates).  Whenever encountering 'A1', i want to increase the count variable.

So the sorted visits look like 

A1 A3 D1 LD  A1 A2 A3 D1

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

Patrick
Opal | Level 21

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;

sas-innovate-white.png

Our biggest data and AI event of the year.

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.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1109 views
  • 0 likes
  • 3 in conversation