Was asked the following question:
2) Create a new variable called HospitalDays that contains the number of days between date of hospitalization and date of either discharge or death. (Hint: SAS dates are stored as days already, so the difference is already expressed in terms of days.)
used the following code:
data hospitaldays;
set cohortwide;
HospitalDays = LastVisitDate death ;
run;
and all of my data is missing. What am I doing wrong here? I followed the steps my professor gave.
Then was later asked this:
3) Create a new variable called Age that is the number of years of age the person
was at the time of symptom onset. (For this, you should try to use the function
shown in the lab demonstration.
Used this code:
data hospitaldays;
Age = event ;
run;
I'm certain that I'm doing something very wrong and may have missed some steps but am wondering how to correct them
data hospitaldays;
set cohortwide;
HospitalDays = LastVisitDate death ;
run;
Maxim 2 — Read the LOG. Surely, the LOG shows errors or warnings here.
data hospitaldays;
Age = event ;
run;
The question asks you to use a function from the lab. You have not used any function here, and of course I don't know what function was used in the lab (although I could guess, I am assuming you know what function was used in the lab, so no point in me guessing).
Furthermore, you are saying that the value of age is the value of event. Please consider the question ... does that make sense? If you had to do this, and you needed to calculate age when an event happened, explain in words (not with SAS or other code) how to calculate the age.
data hospitaldays;
set cohortwide;
HospitalDays = LastVisitDate death ;
run;
Maxim 2 — Read the LOG. Surely, the LOG shows errors or warnings here.
data hospitaldays;
Age = event ;
run;
The question asks you to use a function from the lab. You have not used any function here, and of course I don't know what function was used in the lab (although I could guess, I am assuming you know what function was used in the lab, so no point in me guessing).
Furthermore, you are saying that the value of age is the value of event. Please consider the question ... does that make sense? If you had to do this, and you needed to calculate age when an event happened, explain in words (not with SAS or other code) how to calculate the age.
@saza wrote:
Honestly when it comes to the question about the lab function I should be able to figure it out as long as I can figure out how to write my first code correctly. I included a pic of my lab handout In the original question.
This screen capture does not mention any function. No, you don't need to first figure out how to write your first code correctly to know what function was mentioned in the lab. I'm sure you must know what function was mentioned, so tell us, what function was mentioned.
When I type in the code:
data hospitaldays;
set cohortwide;
HospitalDays = date (death-hospitalized) ;
run;
to get a dataset called "Hospitaldays" from the cohortwide data set, I see that I need to create a new variable called HospitalDays which is equal to the the number of days between the hospital stay and time of death.
I am just having trouble going about this and when I run the code and view my log it says " ERROR 72-185: The DATE function call has too many arguments."
So this is a good place to take a step back and discuss the actual data. If the actual data is dates (in other words, variable DEATH is an actual date and also variable HOSPITALIZED is an actual date, and it appears they are based upon the screen capture you provided) then you simply need to do a subtraction to get the number of days between event and date of hospitalization to get the value of HOSPITALDAYS. Try doing this subtraction without any function whatsoever.
You have avoided the question about AGE at symptom onset. Without discussing any computer code, how would you do this calculation? If you had to do it pencil and paper, please tell us the formula you would use in words.
There are no IF() or THEN() functions in SAS.
There is an IF ... THEN ... STATEMENT.
There are also the IFN() and IFC() functions.
Where is DATE_DISCHARGE and all of those other DATE... variables going to come from? You did not include that variable when you made COHORTWIDE.
The only variables you created are id lastname dob and however many EVENTxxxx variables you created.
Is DATE_DISCHARGE one of the values of EVENT? If so then remove the PREFIX=EVENT option from the PROC TRANSPOSE. With that the variable name would be EVENTDATE_DISCHARGE instead of DATE_DISCHARGE.
What is ~= ? are you trying to test for missing. Use the MISSING() function and the NOT operator and you code will be clearer
if not missing(date_discharge) then ...
Or perhaps skip the IF and use the MIN() or COALESCE() function instead?
HospitalDays = coalesce(Date_Discharge,Date_Death) - Date_Hospitalized;
Some times it helps to add one so that an admission and discharge on the same day counts as one day instead of zero days. An admission on one day and discharge the next is two days (the day of admission and the day of discharge). Etc.
Run a proc contents on the dataset you created in the PROC TRANSPOSE step so you can see the names of the variables.
From this photograph you posted https://communities.sas.com/t5/image/serverpage/image-id/68841iE5F4C4B6C62281DA/image-size/medium?v=...(why post photographs of text?) you could not have gotten a variable named date_discharge. The variable will be named DISCHARGE or EVENTDISCHARGE
@saza wrote:
... however, I'm not trying to create a new variable called "date_discharged"
Sometimes, intermediate variables are created to help in the coding or help in the calculations or help in the debugging. If you don't want the variable, you can delete it any time you want.
Attention to detail is very important in programming, every semicolon matters.
In this case you forgot at least a subtraction/minus symbol in the statement.
If you list two variables how does SAS know what to do with them?
TIP: You can avoid issues like this by commenting your code to state what you're planning to do. Then do it in the code. Then check it in the log AND data.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.