LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 13 Apr 2006 22:16:40 -0400
Reply-To:     PharmaLogic <pharmalogic.llc@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         PharmaLogic <pharmalogic.llc@GMAIL.COM>
Subject:      Re: transfer character variable to numeric variable( date)
Comments: To: toby dunn <tobydunn@hotmail.com>
In-Reply-To:  <BAY101-F18861AA294744229537765DEC00@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1

Yes, silly isn't it, and the code as is is correct. But regarding you other points, some clients require marcos for everything, others require as few as possbile. I even had one that required a macro with proc sql code to put number 1 into a macro var.

The overall idea is consistency in those situations, so that everything is done the same way, and anything possible is done (right), and in that way we can eventually be eliminated (sure).

Good reply. Take Care!

ps. Was the date from a Web Application? -- I think some of the web method applications will take additions to date strings and create something like 31febyyyy, but convert to the correct March date based on a regular or leap year. john

On 4/13/06, toby dunn <tobydunn@hotmail.com> wrote: > > PharmaLogic , > > All I hav to say is why???? Why even create a macro for this? Whether > your > in data step land or macro land reformating or converting dates is such a > trivial matter I doubt its worthy of a macro. And if one was predisposed > to > do so there is absolutely no need for the data step. It would be simplier > to just do it all in pure macro language rather than one that creates data > step code, for the simple case that one it would be easier to write and > two > it could be used at the point of use (ie where it is needed) thus giving > code a more natural read. I dont mean to be hard here but macros can be > used for badness as well as they can be used for good. ANd its up to us > the > programmers to use it wisely. > > > > Toby Dunn > > > > > > From: PharmaLogic <pharmalogic.llc@GMAIL.COM> > Reply-To: PharmaLogic <pharmalogic.llc@GMAIL.COM> > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: transfer character variable to numeric variable( date) > Date: Thu, 13 Apr 2006 21:18:56 -0400 > > A useful macro with example expanded upon you data: > /* -------------------------------------------------------------------- > */ > /* Macro to convert a string date like 20030129175500 to a sas datetime > */ > /* where the string is in the format yyyyMnDyHrMiSe and length=14 > */ > /* -------------------------------------------------------------------- > */ > dm 'log' > clear; > > dm 'out' > clear; > > > > option notes spool ls=132 > ps=60; > > > %macro > conv_date(dsin,dsout,dt_var,dt_out,date_or_dt=DT,show=n,drop_partials=y); > > %* *** Convert a string date to a sas datetime. *** > *;; > > > /* ---------------Example String > Date------------| > | data a; > | > | input dtime $14.; > | > | datalines; > | > | 20030122185000 > | > | 20030925092316 > | > | ; > | > | run; > | > ----------------------------------------------- > */ > > > data > &dsout; > > set > &dsin; > > format date &dt_out._dp date9. &dt_out > datetime20.; > > > date = input(substr(&dt_var,1,8), ?? > yymmdd8.); > > > hr = input(put(input(substr(&dt_var,9,2), ?? > 4.),z4.),4.); > min = input(put(input(substr(&dt_var,11,2), ?? > 4.),z4.),4.); > sec = input(put(input(substr(&dt_var,13), ?? > 4.),z4.),4.); > > > &dt_out = > dhms(date,hr,min,sec); > > &dt_out._dp=datepart(&dt_out); > > > %if %upcase(&drop_partials)=Y %then drop hr min > sec; > > > > run; > > > > %if %upcase(&show)=Y %then > %do; > title Conversion of String > dates; > > > proc print data=&dsout width=min > double; > > run; > > > > > title; > > > > > %end; > > > > %mend > conv_date; > > > > data > a; > > length string_date > $14.; > patient='0001'; string_date='20050228'; > output; > patient='0002'; string_date='20050231'; > output; > patient='0003'; string_date='20050902175203'; > output; > run; > > > > proc print > data=a; > run > cancel; > > > > > > %conv_date(a,b,string_date,realdate,date_or_dt=d,show=y,drop_partials=n); > > > > dm 'out' > top; > > > > > > On 4/13/06, PharmaLogic <pharmalogic.llc@gmail.com> wrote: > > > > Well, it's not a date. There is no Feb 31st. On up to 29th on leap > year. > > > > > > On 4/13/06, Mindy <master2005_sas@yahoo.com> wrote: > > > > > > Hey, guys, > > > > > > I have a question regarding how to transfer a character variable to > SAS > > > date variable. > > > > > > The detail is I have a SAS data set TRY, which including a character > > > variable A such as "20050231", how can I transfer A to numeric > > > variable, which correspondences to Feb31, 2005. The reason of doing > > > this transfer is that I need to calculate the difference of this > > > variable with another date variable. > > > > > > I try to use realdate=input(c_date, yymmdd8.); , but get error > message. > > > > > > Thanks a lot ! > > > > > > Mindy > > > > > > > > > > > -- > > PharmaLogic, LLC > > 484.919.4925 > > PharmaLogic.LLC@gmail.com > > > > > > -- > PharmaLogic, LLC > 484.919.4925 > PharmaLogic.LLC@gmail.com > > >

-- PharmaLogic, LLC 484.919.4925 PharmaLogic.LLC@gmail.com


Back to: Top of message | Previous page | Main SAS-L page