BookmarkSubscribeRSS Feed
Moraes86
Obsidian | Level 7

Hi all,

 

I would like to classify the column "status" in three categories: positive, negative and stable.

 

This classification is based two conditions: date and result.

 

Positive: for less than 30 days and positive result.

Stable: between 30 and 60 days and positive result.

Negative: more than 90 days and negative result.

 

I am posting the information that I have and what I am looking for.

Have     want
                   
date ID Result Test   date ID Result Test Status
1/7/2022 A positive 1   1/7/2022 A positive 1 positive
11/17/2021 A positive 2   11/17/2021 A positive 2 stable
12/12/2021 A negative 3   12/12/2021 A negative 3 negative
1/3/2022 B negative 1   1/3/2022 B negative 1 negative
5/3/2021 B negative 2   5/3/2021 B negative 2 negative

 

 

Thanks all,

 

Daniel

 

12 REPLIES 12
PaigeMiller
Diamond | Level 26

@Moraes86 wrote:

This classification is based two conditions: date and result.

 

Positive: for less than 30 days and positive result.

Stable: between 30 and 60 days and positive result.

Negative: more than 90 days and negative result.


What about other possibilities like positive more than 60 days, negative for fewer than 90 days?

--
Paige Miller
Moraes86
Obsidian | Level 7
This is a great question. Thanks.

For positive more than 60 days: the status is "positive->60days"
For negative fewer than 90 days: the status is "negative".

In addition, for inconclusive result: the status is "unknown".

Thanks again,

Daniel
PaigeMiller
Diamond | Level 26

Any other possible outcomes?

--
Paige Miller
Moraes86
Obsidian | Level 7
No...only these that I mentioned
PaigeMiller
Diamond | Level 26

Please explain row 2 of your data, I don't understand the result.

--
Paige Miller
Moraes86
Obsidian | Level 7
The result is the information that was obtained previously. I will do one correction in the table....because the result is different on the second column related to the information that I want.
PaigeMiller
Diamond | Level 26

Why does the date change in row 2?

 

How do we determine from the data if we are in the 30 day category, or the 60 day category, or the 90 day category?

--
Paige Miller
Moraes86
Obsidian | Level 7
The date change because we have more than one test for each ID. I can add one more column informing it. Does it make sense?
ballardw
Super User

My first question was "how do you calculate days". You state rules in terms of days but do not supply any obvious to me pair of dates that would be used to calculate "days" for the category assignment.

 


@Moraes86 wrote:

Hi all,

 

I would like to classify the column "status" in three categories: positive, negative and stable.

 

This classification is based two conditions: date and result.

 

Positive: for less than 30 days and positive result.

Stable: between 30 and 60 days and positive result.

Negative: more than 90 days and negative result.

 

I am posting the information that I have and what I am looking for.

Have     want
                   
date ID Result Test   date ID Result Test Status
1/7/2022 A positive 1   1/7/2022 A positive 1 positive
11/17/2021 A positive 2   11/17/2021 A positive 2 stable
12/12/2021 A negative 3   12/12/2021 A negative 3 negative
1/3/2022 B negative 1   1/3/2022 B negative 1 negative
5/3/2021 B negative 2   5/3/2021 B negative 2 negative

 

 

Thanks all,

 

Daniel

 


 

Moraes86
Obsidian | Level 7
This is my question as well. I would like to use "today" as a reference of date. For example, today is 01/07/2022, so my question is how to use it to calculate.
ballardw
Super User

@Moraes86 wrote:
This is my question as well. I would like to use "today" as a reference of date. For example, today is 01/07/2022, so my question is how to use it to calculate.

If you want to use the current date and if your current date variable is actually a SAS date then this is easy:

data want;
   set have;
   days = today() - date;
run;

SAS date values are numbers of days, the Today() function returns today's date as date value so subtraction works just fine to get number of days.

If your Date variable is not actually a SAS date value, as in numeric variable and from what you show some sort of mmddyy format then you want to create a date value such as with: SASdate= input(date, mmddyy10.); and use the SASdate in the comparison.

You really want a SAS date valued variable as there are a LOT of things that can be done with them.

Moraes86
Obsidian | Level 7
Ok ballardw. Thank you very much for your help.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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