BookmarkSubscribeRSS Feed
Aishwarya9
Calcite | Level 5

Hi, everyone.

I am trying to create a variable day to find the time to relive from symptoms. The symptoms are evaluated or each day(Day 1 to day 10).For first two day it is evaluated thrice a day and for the remaining its twice a day.

To find the time take for a symptoms to get resolve I have written the code this way

if flag1m="No" or flag1a="No" or flag1e="No" then day=1;
else
if flag2m="No" or flag2a="No" or flag2e="No" then day=2; and so on till day 10.

/*Here 1m means=day1 morning, 2a=day2  afternoon and so on.

This condition works fine and I get the variable day (Time taken to relive from symptoms).

This conditions works fine when the subjects don't get the symptoms once it is resolved but in the data there are few subjects who get the symptoms again once it is resolved For those subjects instead of considering the last day for getting symptoms resolved it considers the  first symptoms resolved day.

If I use the and condition instead of or the day variables for symptoms(repetition) comes fine but for other subjects go wrong.

 

What is the way so that the correct day for symptoms resolved is created?

 

5 REPLIES 5
maguiremq
SAS Super FREQ
Could you please post some example data? If your info contains PHI, please make some example data that we can work from. If it doesn't contain PHI, please use the below macro to create a DATA step containing the data set.

https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

Some additional info on creating data sets in a DATA step:

https://v8doc.sas.com/sashtml/imsdi/z0419000.htm
Aishwarya9
Calcite | Level 5
Hi this is a kind of sample of my data. Like this I have a data for each day that is for day 1 to 2 the measurements are taken thrice a day and for remaining its twice a day
subjid Treatment Fever Cough
1 A Light No
2 B Moderate No
3 A No Moderate
4 B No Light
First I had created a flag variable foe each day each time point that is suppose the above data is for day1 Morning. I have created a flag if fever=No and Cough=No then flag1m=No; else yes.
Similarly i had done the same for remaining days. And after combining all the flags i am trying to create a final variable for day which i have explained as above that is
if flag1m="No" or flag1a="No" or flag1e="No" then day=1;
else
if flag2m="No" or flag2a="No" or flag2e="No" then day=2; and so on till day 10.
where I am finding the issue since some of the subjects get the symptoms again once it get resolved.
Reeza
Super User

Your data isn't clear.

Can you show two data sets please? One should be your input data set, what you start with and the second should be your output data set with the new flagm/flag1e/etc. variables.

If you do it in Excel and paste it over that will be fine for how.

In the long run, data sets that we can run are preferable, see instructions below
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

EDIT: your data has no day or visit identifiers which I would expect to see and I suspect you have more than one person in the data so you may want to expand your example data to be reflective of your use case. Otherwise any answer provided may work for your example data but won't work on your real data.

ballardw
Super User

@Aishwarya9 wrote:
Hi this is a kind of sample of my data. Like this I have a data for each day that is for day 1 to 2 the measurements are taken thrice a day and for remaining its twice a day
subjid Treatment Fever Cough
1 A Light No
2 B Moderate No
3 A No Moderate
4 B No Light
First I had created a flag variable foe each day each time point that is suppose the above data is for day1 Morning. I have created a flag if fever=No and Cough=No then flag1m=No; else yes.
Similarly i had done the same for remaining days. And after combining all the flags i am trying to create a final variable for day which i have explained as above that is
if flag1m="No" or flag1a="No" or flag1e="No" then day=1;
else
if flag2m="No" or flag2a="No" or flag2e="No" then day=2; and so on till day 10.
where I am finding the issue since some of the subjects get the symptoms again once it get resolved.

Generic comment about Yes/no coded variables: For a large number of things it is easier in the long run to code Yes/No as numeric values of 1=Yes and 0=No. For one thing the report procedures like Report and Tabulate, or summary procedures Means and Summary, can get the count of 1 values by summing the variable, the mean of 1/0 coded variable is a decimal percent. When you have multiple variables you can use sum, number of 1's, mean, percent of 1's, min or max functions to tell if any have the value of 0 or 1 from the group, range to test if all are the same value.

 

For example your statement:

if flag1m="No" or flag1a="No" or flag1e="No" then day=1;

if the Flag variables were numeric 1/0 as suggested could be replaced with

if min(flag1m, flag1a,flag1e)= 0 then day=1.

Since I see that you have a variable named Flag1M I might guess that you have at least 13 (a to m) different variables. Which may make some of your comparisons easier using similar code to that shown. Or do you have 30 flag variables (flag1m, flag2m, flag3m, ... flag10m, flag1a,..., flag10a, flag1e, ...,flag10e)?

Typically if you have separate flags per visit the data is in a less than optimal structure.

 

 

The functions such as Min and Max only use non-missing values so needed worry about a missing value getting the min value. The function Nmiss may be useful as it counts actual missing numeric values.

Aishwarya9
Calcite | Level 5
The symptoms are evaluated from day 1 to day 10. Where for the first 3 days symptoms are evaluated thrice (morning, afternoon and evening) and from day 4 to day 10 symptoms are evaluated twice(morning, evening).
So there are datasets for symptoms
day1-3 data's(morning, afternoon and evening)
day1-3 data's(morning, afternoon and evening)
day1-3 data's(morning, afternoon and evening)
day4 -2 data (morning, evening)
'
.
day 10- 2 data's (morning, evening)
So total there will be 23 data sets. I have created a flag variables for each day for each time point (morning, afternoon and evening) for day 1 to 3 and (morning, evening) from day 1 to 10. So there a a total of 23 flags when i merge all those together. After that I was trying to create a final flag as I have mentioned above
if flag1m="No" or flag1a="No" or flag1e="No" then day=1;
else
if flag2m="No" or flag2a="No" or flag2e="No" then day=2; and so on till day 10.
Here No means symptoms is resolved and yes means the subject still has symptoms. i am mainly interested in the No part.
This code works perfectly fine when and I get the correct day for symptoms resolved but few subjects get the symptoms again once it get resolved. For those subjects the day for symptoms resolved gets wrong as it considers the first day day for the symptoms to get resolved even though the symptoms occurs again for the subject . It wont consider the final day for the symptoms to get resolved for those subjects

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 5 replies
  • 882 views
  • 2 likes
  • 4 in conversation