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 2001, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 15 Sep 2001 12:12:06 -0400
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: SYMPUT and SYMGET??
Comments: To: Steve <guitarzealot@YAHOO.COM>
Content-Type: text/plain; charset="iso-8859-1"

Steve,

There are 4 DATA step function (routines) for communicating with the macro facility. Being able to excange data and macro values can be very handy.

CALL SYMPUT - puts data values into macro symbol tables, i.e. it can assign a data value to a macro variable. It can be fairly important. Example.

/* Is a SAS disk data set q empty? */ data _null_ ; call symput ( "NOBS" , left(put(nobs,best12.) ) ; stop ; set q nobs = nobs ; run ;

%put q has &nobs obs. ;

It often appears in old (V6.7-) style macro programs making an array of macro variables from a variable in a SAS data set.

SYMGET - returns a macro variable value as a DATA step value. It is fairly limited in use because the only way to change the value of a macro variable during DATA step execution is to use CALL SYMPUT, in which case the value is already known as a DATA step variable. Example.

/* store macro variables for a restart of program at this point */ data lib.macsys ; set lib.macsys ( keep = macvarname ) ; macvarval = symget ( macvarname ) ; run ;

CALL EXECUTE - sends a string to the macro facility for immeadiate execution during a DATA step. This usually means generate code to be dummped into the input stack for execution when the step finishes. Example.

/* store global variable from data value */ data _null_ ; /* use single quote to hide macro expressions at SAS compile time (could be a macro call) */ call execute ( '% global macvar ; %let macvar = abc ;' ) ; run ;

/* print 10 obs from all sas data sets in libary lib. */ data _null_ ; set sashelp vtable ; where upcase(libname) = "LIB" call execute ( "proc print data = lib." || memname || "9obs = 10) ; run ;" ) ; run ;

So most things that can be done with CALL SYMPUT can also be done with CALL EXECUTE.

RESOLVE - returns the macro evaluation of a macro expression. It is like SYMGET except that it expects an expression in stead of a name. Example.

/* store macro variables for a restart of program at this point */ data lib.macsys ; set lib.macsys ( keep = macvarname ) ; macvarval = resolve ( '&' || macvarname ) ; run ;

IanWhitlock@westat.com

-----Original Message----- From: Steve [mailto:guitarzealot@YAHOO.COM] Sent: Friday, September 14, 2001 12:28 PM To: SAS-L@LISTSERV.UGA.EDU Subject: SYMPUT and SYMGET??

Could someone please explain what these two comands are used for. The only doc I have is too cryptic to really understand.

Thanks

Steve


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