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 (October 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 18 Oct 2006 14:24:56 +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: declare some number as a character variable in macro
Comments: To: hba2pd@GMAIL.COM
In-Reply-To:  <1161150103.120407.212970@b28g2000cwb.googlegroups.com>
Content-Type: text/plain; format=flowed

HBA2PD ,

I see the ussual brtain trust has already answered you immediate question, so let me play David Cassel ( have to Get Davids Name count up there before SUGI) and come on in and expand upon what they already gave you....

The Macro Language and Data Step Languages in SAS have two very different philosophies. Basicall it can be boiled down to this, in the data step language words have meanings ex. data, run, set.... and we the programmers have to designate between what we want SAS to interprete as having meaning and what we want SAS to regard as text. We do this by qouteing the text we want SAS not to interprete as having meaning but as just plain jane text.

While in the macro language everything is considered text and we the programers have to tell SAS what words it is to interprete with some special meaning, we do this with the % and & before these words.

Now lets take this and apply it to your code:

%Let Year = 1991 ;

OKay here SAS sees the % so it knows interprete the following word with meaning orther than plain text. It then sees the Let which it knows of and says okay I am expecting another word 'Year' in this case which will be the name of a macro variable and it also expects a '=' which tells it where to start looking for the value to associate with this macro variable. It finds the '=' and says everything between the '=' and ';' will be assigned to the macro var 'Year'.

Cool at this point you have one macro var created in the global symbol table, its name is 'Year' and its value is '1991'. remember we said everything in the macro facility is just text the 1991 may look like a number to you and me but to SAS it is just plain text as long as we stay in the macro facility.

But lets say you wanted to take this macro vars value and use it in a data step. Okay here we have to decide if we want 1991 to be considered text or a numeric. IF we want it to be a numeric we can simply refernce the macro Year thusly &Year, if however we want it to be considered text we need to put quotes around it so SAS doesnt try to give it meaning beyond just text. Since macro vars wont resolve unless you use double quotes I suggest you use "&Year".

So the syntax would look like:

Data One ;

Year1 = &Year ; Year2 = "&Year" ;

Run ;

Or you could use it in an if statement like:

Data One ;

If ( Year1 = &Year ) Then Do ; .. End ;

If ( Year2 = "&Year" ) Then Do ; .. End ;

Run ;

Or possibly in retain statements:

Data One ; Retain Year1 &Year Year2 "&Year" ; 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.

From: hba2pd <hba2pd@GMAIL.COM> Reply-To: hba2pd <hba2pd@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: declare some number as a character variable in macro Date: Tue, 17 Oct 2006 22:41:43 -0700

Hello,

I would like to declear a number as a character variable in macro. That is,

%let year=1991

I wish to have 1991 as a character variable, not as a numeric variable. How can I do this?

Best regards,

_________________________________________________________________ Add a Yahoo! contact to Windows Live Messenger for a chance to win a free trip! http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-us&hmtagline


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