Help using Base SAS procedures

Proc Report tryng to use where expression

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Proc Report tryng to use where expression

Hi , I'am new in SAS and i'm very excited so far with this amazing and powerful program/tool.

I was wonder if any expert can help me out to get this program to work. I'am trying to use the "where" expression to find a date in a Proc Report procedure but after many web pages , I have not found my answer.here is my code so far;

Proc Report  data=Bomgartestnew nowindows;

  column Composante Day  D__but ("Reçus" Abandon_formule M_A_D );

  define Composante / group descending;

  define abandon_formule /analysis sum "Hier";

  rbreak after / summarize;

where Day eq "Hier"

**another option/***

Where D__but eq '01-05-2015';

***/or using a date format like 01-05-2015 because I have another variable with that kind of observations********/

Run;

It seems that I'm not doing the right thing as both "where" could not find any results and this is the error that I got;

ERROR: WHERE clause operator requires compatible variables

Hoping that someone out there can give me a hand. It would be very appreciate it.

Thanks

Francis


Accepted Solutions
Solution
‎06-11-2015 05:03 PM
Super User
Posts: 5,257

Re: Proc Report tryng to use where expression

The two WHERE statements are failing for very different reasons.

where Day eq "Hier"

The WHERE statement is supposed to examine the incoming observations to determine which ones to use in PROC REPORT.  You can't refer to a calculated field, only to pre-existing fields.  Even if the field existed in the incoming data set, you would have to refer to the variable by its name (ABANDON_FORMULE), not by its label ("Hier").

Where D__but eq '01-05-2015';

SAS stores dates on a different scale that what you are expecting.  It's something you will need to study at some point along the way.  For now, the error message is telling you the D__but is a numeric variable and thus can't be compared to a character string.  D__but probably has a format connected with it that makes it print in MMDDYY form, but its actual value is numeric.  Try this version and see what happens:

Where D__but eq '05JAN2015'd;

Good luck.

View solution in original post


All Replies
Solution
‎06-11-2015 05:03 PM
Super User
Posts: 5,257

Re: Proc Report tryng to use where expression

The two WHERE statements are failing for very different reasons.

where Day eq "Hier"

The WHERE statement is supposed to examine the incoming observations to determine which ones to use in PROC REPORT.  You can't refer to a calculated field, only to pre-existing fields.  Even if the field existed in the incoming data set, you would have to refer to the variable by its name (ABANDON_FORMULE), not by its label ("Hier").

Where D__but eq '01-05-2015';

SAS stores dates on a different scale that what you are expecting.  It's something you will need to study at some point along the way.  For now, the error message is telling you the D__but is a numeric variable and thus can't be compared to a character string.  D__but probably has a format connected with it that makes it print in MMDDYY form, but its actual value is numeric.  Try this version and see what happens:

Where D__but eq '05JAN2015'd;

Good luck.

Occasional Contributor
Posts: 8

Re: Proc Report tryng to use where expression

Thanks very much Astounding for the explanation and it did worked very well. Only thing that I did is that I follow your suggestion and I went back to the data set and predefined a variable with the following statement;

Data Data  Bomgartestnew;

    set Bomgartestnew;

  Day=D__but;

  If Index (D__but,'01-05-2015')   Then Day="Hier";else Day="Mois";

  Mois=D__but;

  If Index (D__but,'05-2015')   Then Mois="Mois";

Run;

So now I can use my Where expression where Day eq "Hier".

You are right I have to know more about  how SAS Stores dates and I will. I've been using SAS for 3 weeks and wow this is awesome !

Thanks  very Much

Assis

Super User
Posts: 9,777

Re: Proc Report tryng to use where expression

Post it at ODS AND REPORT Forum , since it is a question about proc report . Cynthia is there.

Occasional Contributor
Posts: 8

Re: Proc Report tryng to use where expression

Thanks Xia ... I'll do it next time,

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 244 views
  • 0 likes
  • 3 in conversation