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
Content-Type: text/plain; format=flowed
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
So the syntax would look like:
Data One ;
Year1 = &Year ;
Year2 = "&Year" ;
Or you could use it in an if statement like:
Data One ;
If ( Year1 = &Year ) Then Do ;
If ( Year2 = "&Year" ) Then Do ;
Or possibly in retain statements:
Data One ;
Retain Year1 &Year Year2 "&Year" ;
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: hba2pd <hba2pd@GMAIL.COM>
Reply-To: hba2pd <hba2pd@GMAIL.COM>
Subject: declare some number as a character variable in macro
Date: Tue, 17 Oct 2006 22:41:43 -0700
I would like to declear a number as a character variable in macro. That
I wish to have 1991 as a character variable, not as a numeric variable.
How can I do this?
Add a Yahoo! contact to Windows Live Messenger for a chance to win a free