LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 11 Mar 2004 20:42:20 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      look for a simple way to define a macro variable
Comments: To: John Cui <cuij@CSHS.ORG>

John,

You apparently want 50 macro variables, one for each variable in your dataset and have the output or PROC CONTENTS, say C. Then

proc sql ; select name into :myvar1 - :myvar99999999 from c ; quit ;

is the simplest code possible. But then you will have to work with the 50 variables myvar1, .... , myvar50. (SQL doesn't create more variables than needed but it requires an upper bound.)

In most cases this leads to an old style of macro coding which was required because there was no convenient way to make a list. Today (V6.11 or later)

proc sql ; select name into :mylist separated by " " from c ; quit ;

creates one variable holding all the names separated by a space. This usually leads to simpler and better macro code. But it depends on the nature of the problem, and probably the preferences of the programmer since many have grown use to the job security that multiple ampersands provide. If you provide details of how you intend to use the 50 variables then someone will probably provide code to back up my claim.

If you must use %LET and write it only once then the simplest code I know would be

data _null_ ; set c ; call execute ( '%let myvar' || left(put(_n_,8.) || "=" || name || ";" ) ; run ;

Of course 50 %LET's are executed, but the code has only one in it.

Ian_Whitlock@comcast.net


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