| Date: | Sat, 27 Feb 2010 22:08:12 -0500 |
| Reply-To: | art297@NETSCAPE.NET |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Arthur Tabachneck <art297@NETSCAPE.NET> |
| Subject: | Re: Format in SAS |
|
| In-Reply-To: | <530832.99206.qm@web95707.mail.in.yahoo.com> |
| Content-Type: | text/plain; charset="utf-8"; format=flowed |
Mark,
Based on the sample of data you sent me, I would think that the
following will do what you want to accomplish:
data _null_;
infile 'c:\Sas\period1_sales_data3.dat.';
input stuff $35.;
put stuff;
cards;
RX00023609/11/200905:54:52AT3600 1
RX00023709/11/200912:03:14AT3600 1
RX00023810/11/200910:18:34AP3965 1
RX00023910/11/200911:51:29AP3965 1
RX00025511/11/200923:32:19AP3965 1
;
options datestyle=dmy;
data period1;
infile 'c:\Sas\period1_sales_data3.dat.';
Input TransactionID $ 1-8
DateofSale $ 9-18
TimeofSale $ 19-26
LaptopModel $ 27-32
UnitsSold 33-35;
DateTimeofSale = inputn(DateofSale||":"||TimeofSale,'anydtdtm',19);
SameDayDelivery=timepart(DateTimeofSale)<='15:00't;
format DateTimeofSale datetime21.;
run;
Art
-----Original Message-----
From: Mark Chase <mark.chase91@yahoo.in>
To: Arthur Tabachneck <art297@netscape.net>
Sent: Sat, Feb 27, 2010 9:05 pm
Subject: Re: Format in SAS
Hello Arthur ,
I used the code
libname sc 'c:\Cwa';
data  period1;
   infile 'c:\Cwa\period1_sales_data.dat.';
   Input    TransactionID $1-8
         DateofSale    $9-18
         TimeofSale   $19-26
         LaptopModel  $27-32
         UnitsSold     33-35;
proc print data = period1;
run;
and got ( part ) :
Â
                         Transaction                  Timeof   Â
Laptop   Units
                  Obs       ID        DateofSale     Sale    Â
Model     Sold
Â
                   52    RX000236     09/11/2009   05:54:52  Â
AT3600Â Â Â Â Â 1
                   53    RX000237     09/11/2009   12:03:14  Â
AT3600Â Â Â Â Â 1
                   54    RX000238     10/11/2009   10:18:34  Â
AP3965Â Â Â Â Â 1
                   55    RX000239     10/11/2009   11:51:29  Â
AP3965Â Â Â Â Â 1
Then i used code :
data result;
    set period1;
   DateTimeofSale = DateofSale||":"||TimeofSale;
run;
proc print data = result(drop= DateofSale TimeofSale);
run;
and got as output :
   Transaction   Laptop   Units
                    Obs       ID        Model     Sold    Â
DateTimeofSale
Â
                    154    RX000248     AP3965     1    Â
10/11/2009:14:17:28
                    155    RX000253     AP3965     1    Â
11/11/2009:12:22:09
                    156    RX000254     AP3965     1    Â
11/11/2009:13:11:21
                    157    RX000255     AP3965     1    Â
11/11/2009:23:32:19
                Â
I want to extract only those dates on which I've time ">= 15:00:00" in
order to find proprtion of transactions that qualify for same day
delivery and I used code :
data PrepForTabulate /view=PrepForTabulate;
 set result;
 DateofSale=datepart(DateTimeofSale);
 SameDayDelivery=timepart(DateTimeofSale)<='15:00't;
run;
proc print data = PrepForTabulate;
run;
The log ( part ) :-
NOTE: Invalid numeric data, DateTimeofSale='03/11/2009:11:27:53' , at
line 127 column 23.
NOTE: Invalid numeric data, DateTimeofSale='03/11/2009:11:27:53' , at
line 128 column 28.
TransactionID=RX000152 DateofSale=Â TimeofSale=11:27:53
LaptopModel=AP3965 UnitsSold=5
DateTimeofSale=03/11/2009:11:27:53 SameDayDelivery=1 _ERROR_=1 _N_=1
 Kindly guide ,
mark
------------------------------------------------------------
From: Arthur Tabachneck <art297@netscape.net>
To: mark <mark.chase91@yahoo.in>
Cc: SAS-L@LISTSERV.UGA.EDU
Sent: Sun, 28 February, 2010 4:18:11 AM
Subject: Re: Format in SAS
Mark,
Without seeing a sample of your data, it's impossible to know what
will actually work.
That said, the following creates what is hopefully close to what your
data actually looks like, and then inputs it. I had to guess at some
of the lengths and formats as there were a couple of what appeared to
be errors/inconsistencies in your example. Let the list know if this
does, in fact, solve your problem.
*Note: I changed the file name to ....data2 so that you wouldn't
accidentally overwrite your actual data;
data _null_;
 file 'c:\Cwa\period1_sales_data2.dat';
 informat stuff $80.;
 format stuff $80.;
 input stuff;
 put stuff;
 cards;
0000000110APR2004:10:00:01brandx1010
0000000215DEC2009:07:42:01brandy2121
;
data period1 (drop=in_:);
 infile 'c:\Cwa\period1_sales_data2.dat';
 input TransactionID $ 1-8
    in_DateTimeofSale $ 9-26
    LaptopModel $ 27-32
    UnitsSold 33-35
    Warranty 36;
 DateTimeofSale=inputn(in_DateTimeofSale,'datetime',18);
 DateofSale=datepart(DateTimeofSale);
 TimeofSale=timepart(DateTimeofSale);
 format DateTimeofSale datetime21.;
 format TimeofSale time5.;
 format DateofSale date9.;
run;
proc print data=period1;
run;
HTH,
Art
------------
On Feb 27, 2:03Â pm, mark <mark.chas...@yahoo.in> wrote:
> hello ,
>
> I'm using the code :-
>
> data  period1;
> Â Â Â Â infile 'c:\Cwa\period1_sales_data.dat.';
>     Input  TransactionID $1-8
>             DateofSale     $9-18
>             TimeofSale   $19-26
> Â Â Â Â Â Â Â Â @9 DateTimeofSale ANYDTDTM16.
>             LaptopModel  $27-32
>           UnitsSold    33-35
>             Warranty      36;
> format DateTimeofSale datetime21.
> ;
>
> proc print data=period1;
> run;
>
> I want to concatenate the varaibels DateofSale and TimeofSale.The new
> varaible in above code gives no entry.
>
> Kindly  guide,
> markc
------------------------------------------------------------
The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
|