Date: Tue, 30 Dec 2008 10:20:39 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Quickly identify variables by text strings and include them
into array?
In-Reply-To: <BLU132-W5E814CB227890ABFCEA2AC8E70@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1
I believe you have the function just slightly wrong (variable number in the
dataset is the second argument, not format) - actually, I should have given
you a slightly different function if you are using data step:
*data* test;
*set** ht3;*
*array vars (*) _Numeric_**;*
*do i= 1 to** dim(vars);*
* if vinformat(vars(i)) in('date9.'****,'mmddyy10.') then do**;*
*if vars{i} < intnx("day", recentdt, -365) then dateflag+1**;*
*end**;*
*end**;*
*run;*
You may want to use VFORMAT() or VINFORMAT() depending on your data. You
could also use VNAME() - for example:
if find(upcase(vname(vars(i))),'DT') > 0 or
find(upcase(vname(vars(i)))),'DAT') > 0 ...
if that is safer than expecting particular formats/informats.
-Joe
On Tue, Dec 30, 2008 at 10:11 AM, D T <sasandstats@live.com> wrote:
> Joe,
>
> thanks for your response. I tried it, and I am having trouble. Would you
> mind looking at the code and letting me know in case you see an obvious
> mistake or have another suggestion? I ran it with varfmt mmddyy10. (because
> this is what my dates should be in), and with informat date9..
> Still, I am getting a huge amount of error messages like this one:
>
> NOTE: Invalid numeric data, 'date9.' , at line 1000 column 24.
> NOTE: Argument 1 to function VARINFMT at line 1000 column 7 is invalid.
> NOTE: Invalid numeric data, 'mmddyy10.' , at line 1014 column 19.
> NOTE: Argument 1 to function VARFMT at line 1014 column 4 is invalid.
> ERROR: Limit set by ERRORS= option reached. Further errors of this type
> will not be printed.
>
> *data* test;
> *set** ht3;*
> *array vars (*) _Numeric_**;*
> *do i= 1 to** dim(vars);*
> *if varinfmt(vars(i),'date9.'**) or*
> *varfmt(vars(i),**'mmddyy10.') then do**;*
> *if vars{i} < intnx("day", recentdt, -365) then dateflag+1**;*
> *end**;*
> *end**;*
> *run;*
> **
> * Thanks!
> D.
> *
> ------------------------------
>
> Date: Tue, 30 Dec 2008 09:24:45 -0600
> From: snoopy369@gmail.com
> To: sasandstats@live.com
> Subject: Re: Quickly identify variables by text strings and include them
> into array?
> CC: SAS-L@listserv.uga.edu
>
>
> Lots of ways you can do that. Look at the functions that start with the
> letter 'V', such as varfmt() - you could do something as simple as
>
> data test;
> set have;
> array vars _NUMERIC_;
> do i = 1 to dim(vars);
> if varfmt(vars[i])='DATE9.' then do *whatever;
> end;
> run;
>
> Also look at the sashelp documentation on varfmt (and similar functions) as
> it has a very similar example using open() which is more efficient if you
> are trying to do something to the variable and not the data set contents
> themselves.
>
> Finally, if they all START with the same thing, then you can use the :
> operator, say
> DTstuff DTstuff2 DTstuff3
> is all identified by DT: in most functions (for example, x = sum(of DT: )
> would give all DT variables' sum into x).
>
> -Joe
>
>
> On Tue, Dec 30, 2008 at 9:10 AM, D T <sasandstats@live.com> wrote:
>
> I need to run a quick check on all date variables (formatted as dates) in a
> data set, and I have many of them. Is there a way that I could identify the
> date variables quickly within a SAS program to include them into an array?
> The variable names for the dates contain either the text string "dt" or
> "dat". Does anyone have a suggestion?
>
> Thanks!
> D.
> _________________________________________________________________
> It's the same Hotmail(R). If by "same" you mean up to 70% faster.
>
> http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008
>
>
>
> ------------------------------
> Send e-mail faster without improving your typing skills. Get your Hotmail(R)
> account.<http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_speed_122008>
>
|