Date: Thu, 4 Dec 2008 11:42:47 +0000
Reply-To: karma <dorjetarap@GOOGLEMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: karma <dorjetarap@GOOGLEMAIL.COM>
Subject: Re: Finding if Variable Exits or Not
In-Reply-To: <c2192a610812031314k171c2888s2a3746fb5e95f82@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
You are getting these notes as you are mixing up reading the data
sequentially with the how you can read in data with the scl functions
- usually with a lot of looping. Here is a paper that gives examples:
http://www2.umdnj.edu/~linyo/functions.pdf
When using the open function in the datastep, you don't need to close
this as it is implicitly handled by the run statement.
I also think this bit of conditional logic needs changed,
Not Missing(Upcase(Aehind)) ="EPILESPY"
if you are just looking for whether aehind is "EPILEPSY" then
upcase(aehind)="EPILEPSY" is what you are looking for.
For your particular example you can test for the existence of
variables in the same datastep as the conditional logic, using a set
statement.
data names_starting_with_C;
dsid=open('sashelp.class');
name_exists=varnum(dsid,'name'); *check variable existence;
set sashelp.class; *set dataset to traverse;
if name_exists and name=:'C'; *conditonal logic to output names
beginning with C;
run;
proc print;run;
HTH
2008/12/3 SAS_learner <proccontents@gmail.com>:
> As per this Example
>
> Sample *26003: *Programatically determine if a variable exists in a data set I
> did something like this
>
> dsid=open('Aed');
>
> Check =varnum(dsid,'Aehind');
> Check1 =varnum(dsid,'Aehindo');
>
> If Check ^= 0 and Not Missing(Upcase(Aehind)) ="EPILESPY" Then
> Cmindc="EPILEPSY";
> If Check ^= 0 Then Cmindc=Strip(Upcase(Aehind));
> Else If Check1 ^= 0 Then
> Cmindc=Strip(Upcase(Aehindo));
> Else If Cmindc=" ";
>
> But LOG Still have this NOTES Does any body think of avoiding this NOTE:
>
> NOTE: Variable AEHIND is uninitialized.
> NOTE: Variable AEHINDO is uninitialized.
>
> Thanks for Your Time and Help
> SL
> Thanks Joe I am going to explore %Sysfunc as per your Suggestion
>
>
>
>
> On 12/3/08, Joe Whitehurst <joewhitehurst@gmail.com> wrote:
>>
>> You can use %sysfunc and 3 SAS Component Language functions to check
>> for the existence of a variable:
>>
>> 1. %SYSFUNC(OPEN(<data-file-name<,mode>>))
>>
>> 2. %SYSFUNC(VARNUM(data-set-id,var-name))
>>
>> 3. %SYSFUNC(CLOSE(data-set-id))
>>
>> See the online docs for guidance on how to use the SAS Component
>> Language functions mentioned.
>>
>> On 12/3/08, SAS_learner <proccontents@gmail.com> wrote:
>> > I need to find out If a Varible exists in the dataset . So for that I am
>> > trying to do something like this
>> >
>> > *If Not Missing (Aehfrml) then Cmdosfrm = Strip(Upcase(Aehfrml)); *
>> Else
>> > Cmdosfrm=" " ;
>> >
>> > If %Symexist(Aehfrml) Then Do ;
>> > If Not Missing(Aehfrml) then Cmdosfrm = Strip(Upcase(Aehfrml));
>> > End ;
>> > Else Cmdosfrm=" " ;
>> >
>> > If Not Missing(Aehmddf)and Not Missing (Aehmdd) then Cmdostxt =
>> > Strip(Aehmddf) ;
>> > Else
>> Cmdostxt
>> > = "" ;
>> >
>> > When I do Not Missing () does it checks if a variable exits or does have
>> any
>> > values ??
>> >
>> > and Can I use %Symexist inside the datastep if not is there a call
>> routine
>> > that I can
>> >
>>
>