BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rakesh93
Calcite | Level 5
How to assign visitnum when all the Tests are done on same date?
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Rakesh93 wrote:
How to assign visitnum when all the Tests are done on same date?

You really should show a brief example of your input data and what you would expect the output to look like.

And if your dates are not SAS Date values then creating such will be the first step.

I am guessing that you want the same visit number for each test on the same day and that the count should start over based on some sort of ID variable(s).

 

Here may be one way:

data have;
   input id date :date9. test $;
   format date date9.;
datalines;
1  01Jan2019 A
1  01Jan2019 B
1  01Jan2019 Q
1  01Jan2019 T
1  04Jan2019 Q
1  04Jan2019 T
1  08Jan2019 Z
1  08Jan2019 R
;

/* Next step Assumes the data is actually 
sorted by Id and date
*/

data want;
   set have;
   by id date;
   retain visitnum;
   if first.id then visitnum=1;
   else if first.date then visitnum+1;
run;

If it takes more than a single variable to identify an individual then you may need to provide a more detailed example.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Show us a portion of your data.

--
Paige Miller
Astounding
PROC Star

The computer is only a tool to carry out your wishes.

 

If you had the data sitting in front of you, and a pencil, what values would you assign?  Give an example.

ballardw
Super User

@Rakesh93 wrote:
How to assign visitnum when all the Tests are done on same date?

You really should show a brief example of your input data and what you would expect the output to look like.

And if your dates are not SAS Date values then creating such will be the first step.

I am guessing that you want the same visit number for each test on the same day and that the count should start over based on some sort of ID variable(s).

 

Here may be one way:

data have;
   input id date :date9. test $;
   format date date9.;
datalines;
1  01Jan2019 A
1  01Jan2019 B
1  01Jan2019 Q
1  01Jan2019 T
1  04Jan2019 Q
1  04Jan2019 T
1  08Jan2019 Z
1  08Jan2019 R
;

/* Next step Assumes the data is actually 
sorted by Id and date
*/

data want;
   set have;
   by id date;
   retain visitnum;
   if first.id then visitnum=1;
   else if first.date then visitnum+1;
run;

If it takes more than a single variable to identify an individual then you may need to provide a more detailed example.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 726 views
  • 0 likes
  • 4 in conversation