BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASbeginnerEPI
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

 

 

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

 

 

 

SASbeginnerEPI
Calcite | Level 5

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.

ballardw
Super User

@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.

 

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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