Hello,
I'm very new to SAS and I'm trying to compute a column in a report that generates a text string based on a comparison of the ENDDATE column to today(). I must have an error, because the computed column consistently returns 'Closed' even for dates >= today(). Help is appreciated! Here is what I've gotten so far:
Proc Report data=outbreaks;
Column OUTBREAKNAME ONSET ENDDATE STATUS;
Define OUTBREAKNAME /group 'Outbreak Name';
Define ONSET /analysis min 'Start Date';
Define ENDDATE /analysis max 'End Date';
Define STATUS / computed 'Status';
Title 'Outbreak Status';
Compute STATUS / char length=20;
If ENDDATE >= today()
then STATUS= 'Active / Ongoing';
Else STATUS= 'Closed';
Endcomp
Run;
Data is nice.
When I make dummy set to check your code:
data junk; enddate = '31DEC9999'd; run; proc report data=junk; columns enddate status; Define ENDDATE /analysis max 'End Date'; Define STATUS / computed 'Status'; Compute STATUS / char length=20; If ENDDATE >= today() then STATUS= 'Active / Ongoing'; Else STATUS= 'Closed'; Endcomp ; Run;
The log shows:
21 proc report data=junk; 22 columns enddate status; 23 Define ENDDATE /analysis max 'End Date'; 24 Define STATUS / computed 'Status'; 25 Compute STATUS / char length=20; 26 If ENDDATE >= today() 27 then STATUS= 'Active / Ongoing'; 28 Else STATUS= 'Closed'; 29 Endcomp ; 30 Run; NOTE: Variable ENDDATE is uninitialized. NOTE: There were 1 observations read from the data set WORK.JUNK. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
You did read the log didn't you?
See the difference below.
32 proc report data=junk; 33 columns enddate status; 34 Define ENDDATE /analysis max 'End Date'; 35 Define STATUS / computed 'Status'; 36 Compute STATUS / char length=20; 37 If ENDDATE.max >= today() 38 then STATUS= 'Active / Ongoing'; 39 Else STATUS= 'Closed'; 40 Endcomp ; 41 Run; NOTE: There were 1 observations read from the data set WORK.JUNK. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
There are times you have to reference the statistic of a variable.
Data is nice.
When I make dummy set to check your code:
data junk; enddate = '31DEC9999'd; run; proc report data=junk; columns enddate status; Define ENDDATE /analysis max 'End Date'; Define STATUS / computed 'Status'; Compute STATUS / char length=20; If ENDDATE >= today() then STATUS= 'Active / Ongoing'; Else STATUS= 'Closed'; Endcomp ; Run;
The log shows:
21 proc report data=junk; 22 columns enddate status; 23 Define ENDDATE /analysis max 'End Date'; 24 Define STATUS / computed 'Status'; 25 Compute STATUS / char length=20; 26 If ENDDATE >= today() 27 then STATUS= 'Active / Ongoing'; 28 Else STATUS= 'Closed'; 29 Endcomp ; 30 Run; NOTE: Variable ENDDATE is uninitialized. NOTE: There were 1 observations read from the data set WORK.JUNK. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
You did read the log didn't you?
See the difference below.
32 proc report data=junk; 33 columns enddate status; 34 Define ENDDATE /analysis max 'End Date'; 35 Define STATUS / computed 'Status'; 36 Compute STATUS / char length=20; 37 If ENDDATE.max >= today() 38 then STATUS= 'Active / Ongoing'; 39 Else STATUS= 'Closed'; 40 Endcomp ; 41 Run; NOTE: There were 1 observations read from the data set WORK.JUNK. NOTE: PROCEDURE REPORT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
There are times you have to reference the statistic of a variable.
Thank you! That solved it. I did read the log, but I admit I'm still learning HOW to read the log and make sense of it. I really appreciate the quick response and solution.
@SASbeginnerEPI wrote:
Thank you! That solved it. I did read the log, but I admit I'm still learning HOW to read the log and make sense of it. I really appreciate the quick response and solution.
The clue in this case from the log was the "uninitialized". SAS uses that when a variable exists but a value has not been assigned.
Since the variable exists and has values, what would be "uninitialized" is the question. So we look at how the variable is used and the Analysis gives us a clue that the statistic may be wanted.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.