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
Content-Type: text/plain; format=flowed
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. )
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:
Library = ProjAInt ;
Modify Dataset1 ;
Var87 GenPurpose. ;
Modify Dataset2 ;
Format Var12 GenPurpose. ;
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
From: Hari <excel_hari@YAHOO.COM>
Reply-To: Hari <excel_hari@YAHOO.COM>
Subject: Reading value labels from SAS file
Date: Mon, 11 Sep 2006 11:56:37 -0700
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";
b) Now, second part is applying the above created single format
GenPurpose to different variables in different data sets.
Options FMTsearch = (MyFmtLib.MyProjCat)
%Macro FormatMe (DatasetLibrary, DatasetName,TargetVar);
Proc Datasets Library = &DatasetLibrary;
Format &TargetVar GenPurpose.;
/*Now calling the above macro iteratively for each relevant variable in
%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.