Date: Sun, 1 Sep 1996 07:17:35 -0500
Reply-To: Benjamin Clardy <bkc@NYQUIST.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Benjamin Clardy <bkc@NYQUIST.COM>
Organization: All USENET -- www.net-link.com
Subject: Re: Checking Variables? (Nobs?)
C. Sakamoto (NCHL League President) wrote:
>
> I was wondering if someone could explain to me how to carry out
> the following (I'm kinda new at this SAS stuff....):
>
> I have a TON of archived data that now has to be changed (SIGH).
> But only certain variables are changing (just a simple rename),
> but I have to check the datasets first to see if the variables
> even exists for that year...
>
> (IE: Dataset-1992 has variable X, but 1993 may not).
>
> What I am hoping to do is to set the dataset, check if there
> are any observations with that variable (nobs) and if so
> rename it...if not don't. Simple but I can't seem to
> get it done. I have a program that takes in all the
> variable names (and dataset) and makes the changes, but
> it doesn't do the check...and if the variable doesn't
> exist then of course, the dataset gets overwritten
> with a 0 variable dataset...(yeesh....did that make
> sense?!).
>
> Thanks ahead of time for any help!!!
>
> -----------------------------------------------------
> Chris Sakamoto
> Email: sakamoto@cpsc.ucalgary.ca
> World Wide Web: http://www.cpsc.ucalgary.ca/~sakamoto
> -----------------------------------------------------
I beleive PROC CONTENTS has an option to output the contents of the
dataset into another dataset. If not, you could use PROC PRINTO
to redirect the listing into a text file that you then parse and
read back into SAS using a %INCLUDE statement.
In either case, a bit of macro code can check to see if the
dataset has what you need.
Also, you might look at PROC DATASETS. I believe it is more
forgiving if the variables to be renamed do not exist.
Benjamin
|