Date: Mon, 11 Sep 2006 19:09:44 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Reading value labels from SAS file
In-Reply-To: <1158000997.104238.221130@p79g2000cwp.googlegroups.com>
Content-Type: text/plain; format=flowed
Hari ,
1.) Use Data Step and Proc Format CntlIn option.
2.) Your macro is to darn all encompasing. By that I mean it is trying to
do too much.
%Macro FormatVar( DSN = , VarList = , FMT = ) ;
Modify &DSN ;
Format &VarList &FMt ;
%Mend FormatVar ;
Use It like:
Proc DataSets Library = ProjAInt ;
%FormatVar( DSN = DataSet1 , VarList = Var1 Var2 Var3 , FMT = MYFMT. )
..
..
..
..
Run ;
Quit ;
Which now begs the question why use a macro at all if you still have to
specify all of the vars and data sets names and formats.
In stead of the macro try the following:
Proc Datasets
Library = ProjAInt ;
Modify Dataset1 ;
Format Var23
Var33
Var87 GenPurpose. ;
Modify Dataset2 ;
Format Var12 GenPurpose. ;
Quit;
Toby Dunn
When everything is coming at you all at once, your in the wrong lane.
A truly happy person is someone who can smile and enjoy the scenery on a
detour.
From: Hari <excel_hari@YAHOO.COM>
Reply-To: Hari <excel_hari@YAHOO.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Reading value labels from SAS file
Date: Mon, 11 Sep 2006 11:56:37 -0700
Hi,
I have 10 SAS data sets which have different kinds of information and
common ID's linking the data sets to each other.
In each of these data sets there is atleast one variable for which the
equivalent text description is stored in a variable called
"GeneralPurposeValueDescrip" existing in the 11th data set. The
equivalent ID to look up is "GeneralPurposeValueID". This 11th data set
has 3800 records.
Since SAS has the wonderful feature of Formats so I thought that I
would create a format by using the above 2 columns and then apply the
format one by one to the relevant variables in each of the data sets.
To that end:-
a) I first exported the 11th data set to excel (view in excel) and then
concatenated the GeneralPurposeValueID and GeneralPurposeValueDescrip
to get the syntax for Proc Format and created a catalog in a particular
location within my project folder.
Proc Format Library = MyFmtLib.MyProjCat;
value GenPurpose(Default = 147)
1 = "PC with a Camera"
2 = "Single"
3 = "> than 100 Employees"
....
....
3799 = "High-School";
Run;
b) Now, second part is applying the above created single format
GenPurpose to different variables in different data sets.
Something like,
Options FMTsearch = (MyFmtLib.MyProjCat)
options nofmterr;
%Macro FormatMe (DatasetLibrary, DatasetName,TargetVar);
Proc Datasets Library = &DatasetLibrary;
modify &DatasetName;
Format &TargetVar GenPurpose.;
Quit;
%Mend FormatMe;
/*Now calling the above macro iteratively for each relevant variable in
the dataset*/
%FormatMe(ProjAInt, Dataset1, Var33);
%FormatMe(ProjAInt, Dataset1, Var87);
%FormatMe(ProjAInt, Dataset1, Var23);
%FormatMe(ProjAInt, Dataset2, Var12);
and so on and on.
I want to know as to whether there are easier ways to achieve what am
doing above? Is there a way I can call the macro only once for the
relevant variables in that data set rather than calling for each
variable? Any other ideas for improving the above would be welcome.
Regards,
HP
India