Date: Wed, 4 Oct 2006 15:19:51 -0400
Reply-To: Nathaniel_Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject: Re: This is regarding DATE format
In-Reply-To: <1159987971.580731.228510@k70g2000cwa.googlegroups.com>
Content-type: text/plain; charset=US-ASCII
VJ
Do you mean that if the date is good meaning that it is written with / and
not - and that it has a four digit year and if it has a valid account
number, you want it to go into X while if it it should go into Badguys if
it fails any of these tests?
This appears to be what my code does but it writes the entire record with
both date values to badguys if a test fails. Do you mean that you want only
the dates that fail to be written to badguys? I think that the code below
may be closer to what you want. Please note that I have used more data
steps than is really necessary. I wrote it this way to make it easier to
read.
Nat
DATA X ;
informat Acctnum $5. invdate invduedt $10.;
INPUT Acctnum invdate invduedt ;
* do not read these using sas informats since that converts them to SAS
dates and you will
not be able to check for the original formating.;
/*
INVDATE MMDDYY8.
INVDUEDT MMDDYY8.
; */
CARDS;
A123 1/7/2004 2/29/2004
B234 3/8/2004 4/8/2004
C1122 05-09-05 4/8/2004
D2233 3/8/2004 03/09/04
. 3/8/2004 4/8/2004
. 3/9/2004 5/9/2004
. 2/8/2004 4/6/2004
. 4/8/2004 6/5/2004
C1122 02-09-06 4/8/2004
D2233 3/8/2004 03/09/08
;
data x;*create two records from each input record;
set x;
drop invd: ;* this is a shorthand way to refer to all variables
whose names start invd ;
oldvar='Invdate ';
Date= invdate;
output;
oldvar='Invduedt';
Date=invduedt;
output;
Data x badguys;
set;
if acctnum = ' ' then output badguys;
else if index(date,'-') then output badguys ;
else do;
test1=scan( date,3,'/');
if length(test1) lt 4 then output badguys;
else output x;
end;
proc print data=x;title 'set x';
proc print data=badguys;title 'set badguys';
run;
vj
<vijay_sas@HOTMAI
L.COM> To
Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
Discussion" cc
<SAS-L@LISTSERV.U
GA.EDU> Subject
Re: This is regarding DATE format
10/04/2006 02:52
PM
Please respond to
vj
<vijay_sas@HOTMAI
L.COM>
Hi Wood,
Great help. I have learnt from you.Toby also suggested me very nicely.
A little Confusion. I couldn't have explained exactly. I need to write
05-09-05 or 05/09/06 like formats in badguys. And Null values of
Account numbers also.( I need to write year two digit values will write
in badguys.)
All the four digit year date values should write in x except Account
number have Null values.
If possible please write again. I check tomorrow morning.
Thanks much... I am a lucky person got immediately answer from you.
Vj.
Nat Wooding wrote:
> VJ
>
> This is basically what Toby suggested. I left the two variables Test1 and
> Test2 in the final set just so you could see what they looked like. You
> could actually write the program without creating the two variables but I
> like to actually be able to see them.
>
> Nat Wooding
>
> DATA X badguys;
> informat Acctnum $5. invdate invduedt $10.;
> INPUT Acctnum invdate invduedt ;
> * do not read these using sas informats since that converts them to SAS
> dates and you will
> not be able to check for the original formating.;
> /*
> INVDATE MMDDYY8.
> INVDUEDT MMDDYY8.
> ; */
> if acctnum = ' ' then output badguys;
> else if (index(invdate,'-') or index(invduedt,'-') ) then output badguys
;
> else do;
> test1=scan(invdate,3,'/');
> test2=scan(invduedt,3,'/');
> if length(test1) lt 4 or length(test2) lt 4 then output badguys;
> else output x;
> end;
> CARDS;
> A123 1/7/2004 2/29/2004
> B234 3/8/2004 4/8/2004
> C1122 05-09-05 4/8/2004
> D2233 3/8/2004 03/09/04
> . 3/8/2004 4/8/2004
> . 3/9/2004 5/9/2004
> . 2/8/2004 4/6/2004
> . 4/8/2004 6/5/2004
> C1122 02-09-06 4/8/2004
> D2233 3/8/2004 03/09/08
> ;
>
> proc print data=x;title 'set x';
> proc print data=badguys;title 'set badguys';
> run;
>
>
>
> vj
> <vijay_sas@HOTMAI
> L.COM>
To
> Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
> Discussion"
cc
> <SAS-L@LISTSERV.U
> GA.EDU>
Subject
> This is regarding DATE format
>
> 10/04/2006 12:01
> PM
>
>
> Please respond to
> vj
> <vijay_sas@HOTMAI
> L.COM>
>
>
>
>
>
>
> Hi All,
> Please help me to finish this query.
> I have three variables in a dataset and I have to remove null values of
> acctnum and I want to abend if the invdate, invduedt is like mm-dd-yy
> or mm/dd/yy.
>
>
> Example:
>
> DATA X;
> INPUT Acctnum $20.
> INVDATE MMDDYY8.
> INVDUEDT MMDDYY8.
> ;
> CARDS;
> A123 1/7/2004 2/29/2004
> B234 3/8/2004 4/8/2004
> C1122 05-09-05 4/8/2004
> D2233 3/8/2004 03/09/04
> . 3/8/2004 4/8/2004
> . 3/9/2004 5/9/2004
> . 2/8/2004 4/6/2004
> . 4/8/2004 6/5/2004
> C1122 02-09-06 4/8/2004
> D2233 3/8/2004 03/09/08
> ;
> RUN;
>
> i) i want to delete the records which have Acctnum is NULL.
> ii) I want to abend if the data have 05-09-05(mm-dd-yy) format or
> like 01/02/05 (mm/dd/yy)format.
> I mean can write to abend file.
>
> Please help me to write this program..
> Thank you very much in Advance..
> Can you please mail me Urgent.
>
>
>
> -----------------------------------------
> CONFIDENTIALITY NOTICE: This electronic message contains
> information which may be legally confidential and/or privileged and
> does not in any case represent a firm ENERGY COMMODITY bid or offer
> relating thereto which binds the sender without an additional
> express written confirmation to that effect. The information is
> intended solely for the individual or entity named above and access
> by anyone else is unauthorized. If you are not the intended
> recipient, any disclosure, copying, distribution, or use of the
> contents of this information is prohibited and may be unlawful. If
> you have received this electronic transmission in error, please
> reply immediately to the sender that you have received the message
> in error, and delete it. Thank you.