Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problem 1

Status
Not open for further replies.

irinnew

Technical User
Mar 19, 2005
81
US
Hi everybody,

I run the following code and it looks like my nonbase_dt field data are presented improperly because my log told that set OUT.BASEEARL has 0 observations while it has a lot


21 data out.baseEarl;
22 set out.baseEarl;
23 by memberid nonbase_dt;
24 if nonbase_dt le datepart(01/01/2002) THEN grptag="before";
25 else if grptag="after";
26 run;

NOTE: There were 2896 observations read from the data set OUT.BASEEARL.
NOTE: The data set OUT.BASEEARL has 0 observations and 35 variables.



This is the fragment of my Proc Contents:

# Variable Type Len Pos Format Informat Label
---------------------------------------------------------------------------------
26 nonbase_dt Num 8 176 MMDDYY10.


How should I fix my code?

Thanks i advance,

Irin



 
been a while since I have been in SAS, but dont you specify dates just a bit differently?

Would this do it?
Code:
nonbase_dt <= '1JAN2002'D

again - been a while, but...

 
Irennew,
Your date var is a regular SAS date value. Therefore you do not use the datepart function when testing for a particular date value. Jymm is correct, you should test by doing the following.

Code:
 if nonbase_dt le '01JAN2002'd THEN 
    grptag = "before";
 else
   grptag = "after";

I hope that this helps you.
Klaz

You can also use the actual SAS date value for that day, 15341.
 
Also, there's an extra if in
Code:
25         else if grptag="after";
Generally I avoid writing out to the input dataset if at all possible, it makes re-running complicated.

The reason that you end up with 0 observations is that extra "if", it fails to meet the first criteria, so moves to the ELSE, the else statement basically tells it to only progress is grptag = 'after', which it never will be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top