LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 1 Sep 2006 18:05:10 +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: OT: RE: Select column names based on the column values
Comments:   To: JClark@CHPDM.UMBC.EDU
In-Reply-To:   <8B5E9B95CC245C46A68BF4495A29A7EEB3C35D@chpdm-mail.chpdm.umbc.edu>
Content-Type:   text/plain; format=flowed

Jack ,

It means you have a design flaw in your macro design and/or program. Pretty broad statement huh!!! It is true though. To be more specific it generally means your design is too closely tied to the data and you havent abstracted the problem out enough.

Think about it this way, good macro design requires that it be abstracted enough from the data and data structure such that it has resuability. This reusability is what gives a macro its power to do both good and unfortunantly bad. The question of parameters comes down to what drives the macro itself. Which is meta data that cant be derived by the macro itself and still stay abstracted from the data and/or data structure. At the very least it should have a parameter passing the data set name to use.

Lets consider a very simple example:

%Macro PrintIt ; Proc Print Data = XYZ ; Run ; %Mend PrintIt ;

Okay this is a very simple macro but the problem with it is the fact that it is perfectly tied to the data XYZ. Not very useful when you need to print different data sets. Also it is no different than if you didnt have the macro wrapper. In essence you have to change the inner working of the macro inorder to make it usefull for some other data set.

So lets rewrite it something like:

%Macro PrintIt( DataIn = ) ; Proc Print Data =&DataIn ; Run ; %Mend PrintIt ;

Now we can just call the macro as much as we want no problems fiddling with the its innards.

We could have just as easily done the following:

%Macro PrintIt ; Proc Print Data =&DataIn ; Run ; %Mend PrintIt ;

No parameter but it also means the user has to know that the macro requires a global macro variable called Datain. This is a train wreck waiting to happen for so many reasons that have been stated so many time already on SAS-L.

You specifically mentioned %If-%then statements. Okay fair enough.... The values for them to compare too have to come from somewhere. The question you need to ask is where should they come from and when? These values must come from either a step before the %If-%Then or they must come from somewhere outside of the macro. If it is the former then the intial data set name needs to be passed in as a parameter. Then pass the %If-%Then Values in as parameters.

Now having said all of this and waiting for Ian to come in and beat me about my head and upper thorax region with his corrections. One can make a case for a System D type programming approach. System D is a culinary term used to refer to a cook who is willing to cut a few but not all corners, to avoid or get a kitchen out of the weeds during a rush. In programming terms it is a mercenary type programmer who in the thick of things with looming dead lines, bosses who are all up in there face about getting this project turned out ASAP (mainly due to the bosses inability to set doable deadlines), or simply helping another programmer out of the weeds is able to step in and cut a few corners here or there use a few tricks of the trade and get the deliverables out the door. In these cases it may be advantagous to simply say the hell with proper design and just bang out the code in what ever way they can get it too work.

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: Jack Clark <JClark@CHPDM.UMBC.EDU> Reply-To: Jack Clark <JClark@CHPDM.UMBC.EDU> To: SAS-L@LISTSERV.UGA.EDU Subject: OT: RE: Select column names based on the column values Date: Fri, 1 Sep 2006 13:09:34 -0400

Toby,

I sometimes use macro programs with no parameters to take advantage of the macro language statements (%IF-%THEN, conditionally executing PROCS, etc.).

What is it that you hate about macros without parameters? Is it a personal preference thing, or is there something I could learn about programming clarity or efficiency?

Thanks.

Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of toby dunn Sent: Friday, September 01, 2006 12:24 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Select column names based on the column values

Sekhar ,

I will offer a slightly different perspective here in so much as I dont like writing macros when I feel one isnt needed and I especially hate macros that among other things have no parameters.

So here is my humble non-macro solution:

Data Test ; Input Col1 Col2 Col3 ; Cards; 23 40 30 -100 30 40 25 -100 35 ; Run ;

ODS Listing Close ; ODS Output OneWayFreqs = Freqs ;

Proc Freq Data = Test ; Table _Numeric_ ; Run ;

ODS Listing ;

Data VarNames ( Keep = VarNames ) ; Length VarNames $ 200 ; Set Freqs ; By Table ;

If ( First.Table And ( VValueX( Scan( Table , 2 , ' ' ) ) = -100 ) ) ;

VarNames = Scan( Table , 2 , ' ' ) ;

Run ;

Proc SQL NoPrint ; Select VarNames Into: Vars Separated By ',' From VarNames ;

Create Table New As Select &Vars From Test ; Quit ;

Proc Print Data = New ; Run ;

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.

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Sekhar Sent: Friday, September 01, 2006 10:40 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Select column names based on the column values

Hi How can I select the coulmn names based on the column values. For example col1 col2 col3 23 40 30 -100 30 40 25 -100 35

In this I want to select all the column names having minimum value of -100. can I use sashelp.vcolumn.

Thanks for the help.


Back to: Top of message | Previous page | Main SAS-L page