Date: Wed, 3 Mar 2010 15:36:47 -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: check for variable existence, if not there put variable in.
In-Reply-To: <4B8E80FC020000C7000C014A@kumc-smtpout.kumc.edu>
Content-Type: text/plain; charset=ISO-8859-1
You can always put
if missing(var) then call missing(var);
which is sort of cheating but works fine iff var is numeric...
Or just give the variable a format and/or length - that will initialize the
variable if it's not in existence at that point.
-Joe
On Wed, Mar 3, 2010 at 3:32 PM, Catima Potter <cpotter@kumc.edu> wrote:
> Hello,
>
> I am writing code where I need to see if a variable exists in the
> dataset. If it is not there, then I would like to include it with a
> value of . (missing). I have tried this code but when the variable does
> exists, it is overwriting the values to missing. Your assistance is
> greatly appreciated. ~Catima
>
>
> data have;
> input _20093 _20094 rate $;
> cards;
> 3 1 staffing
> 5 2 staffing
> 7 3 staffing
> 9 4 staffing
> 11 5 staffing
> 13 6 staffing
> 15 7 staffing
> 17 8 staffing
> 19 9 staffing
> ;
>
> %let pastyrqtr = _20093;
> data have;
> set have;
> if symexist('&pastyrqtr') then put '**** &pastyrqtr exists';
> else &pastyrqtr = .;
> run;
>
|