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.

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

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