sas >> macro variable holding more than one value - problem defined clearly

by aarumugam » Sun, 20 Jun 2004 03:04:26 GMT

Ok.
I have only one macro variable that is created in Proc SQL.

%macro runit(name);
proc sql;
select count(*) into :nObs, '&name' into :fullName from tab1;
quit;

%mend runit;

%runit(John);
%runit(Smith);

data _null_;
if &nObs >0 then;
put "My full name is : &fullName";
run;

output expected:
My full name is John Smith

oupput I got:
Smith

Sorry for not being clear. Now I think I am clear. My real intention is to
get John Smith, not Smith. The macro runit cannot produce John Smith. What
modification I should do the make the code work?

Help Please.

Thanks,
AA


sas >> macro variable holding more than one value - problem defined clearly

by jim.groeneveld » Sun, 20 Jun 2004 05:58:53 GMT






Hi Anbu,

No, you don't get just Smith, you get:
My full name is : John
My full name is : Smith

To get what you want this rather cumbersome ways is:
%Runit (John Smith);

Your macro, using SQL could as well have contained a _NULL_ data step with
CALL SYMPUT, or even more direct just a macro statement %LET Fullname = .
While showing the value with the _NULL_ data step the statement
if &nObs >0 then;
is of no use at all and may be removed.
Instead of all that just a macro %PUT statement will do as well.

Just tell us what it is that you actually want, making it possible for us to
point you to a specific direction.

Regards - Jim.



sas >> macro variable holding more than one value - problem defined clearly

by jim.groeneveld » Mon, 21 Jun 2004 16:11:52 GMT

Hi Anbu,

You might want something like this:

%macro runit(name);
%LET FullName = &FullName &Name;
%mend runit;

%LET FullName = ;
%runit(John);
%runit(Smith);

%put My full name is: &fullName;

Is that what you need indeed?

Regards - Jim.

. . . . . . . . . . . . . . . .

Jim Groeneveld, MSc.
Biostatistician
Science Team
Vitatron B.V.
Meander 1051
6825 MJ Arnhem
Tel: +31/0 26 376 7365
Fax: +31/0 26 376 7305
XXXX@XXXXX.COM
www.vitatron.com

Showing statistically significant differences between football teams,
generally all sporters, requires larger samples than usually applied.

[common disclaimer]


-----Original Message-----
From: Anbu Arasu [mailto: XXXX@XXXXX.COM ]
Sent: Saturday, June 19, 2004 21:04
To: XXXX@XXXXX.COM
Subject: Re: macro variable holding more than one value - problem
defined clearly


Ok.
I have only one macro variable that is created in Proc SQL.

%macro runit(name);
proc sql;
select count(*) into :nObs, '&name' into :fullName from tab1;
quit;

%mend runit;

%runit(John);
%runit(Smith);

data _null_;
if &nObs >0 then;
put "My full name is : &fullName";
run;

output expected:
My full name is John Smith

oupput I got:
Smith

Sorry for not being clear. Now I think I am clear. My real intention is to
get John Smith, not Smith. The macro runit cannot produce John Smith. What
modification I should do the make the code work?

Help Please.

Thanks,
AA


macro variable holding more than one value - problem defined clearly

by aarumugam » Tue, 22 Jun 2004 08:35:39 GMT

On Mon, 21 Jun 2004 10:11:52 +0200, Groeneveld, Jim



OK. I want to concatenate the values in each call of the macro.

var1=var1 || var2;

This is the requirement. But how do I will do it in the above said
condition.

Thanks,
AA


Similar Threads

1. macro variable holding more than one value

Hi All,
   I want to create a macro varible holding two or more values from two or
more macro calls.
OPTION SYMBOLGEN MPRINT MLOGIC;
%LET IDVAL;
%LET PERSON;

data a;
input ID;
datalines;
1
2
;

%MACRO CALLS(PER);
PROC SQL;
*create table  x1 as;
  SELECT
     ID,
     "&&PER" AS MAN
  INTO :IDVAL ,
       :PERSON SEPARATED BY ',' FROM A;
QUIT;
%MEND CALLS;
%CALLS(John);
%CALLS(Smith);

%PUT &IDVAL;
%PUT &PERSON;


Here at the end of the second call "Smith", I am seeing the value of only
Smith, but not "John, Smith".

Help please.

Thanks

2. Macro variable is not long enough to hold my intended value

3. "Missing" macro values, was: Macro Variable Problem

Hi Toby,

I agree 99.99% with you. And as far as empty or missing macro values is concerned, I think it merely is a matter of naming such values. Because missing dataset values are treated as missing automatically by statistical PROCs, they are special, regarded missing. Missing macro values never are treated differently, special in any way. That is why I prefer not to call them missing, to avoid confusion. But you and I know what we mean, what those values are. And if you or anyone else prefer to call them missing, I don't mind. So, after all, I think we only disagree for .01%, just about a name for the concept.

Well Toby, I liked this discussion ;-)

Regards - Jim.
.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .

Jim Groeneveld, MSc.
Biostatistician
Science Team
Vitatron B.V.
Meander 1051
6825 MJ  Arnhem
Tel: +31/0 26 376 7365
Fax: +31/0 26 376 7305
 XXXX@XXXXX.COM 
www.vitatron.com

Showing statistically significant differences between football teams,
generally all sporters, requires larger samples than usually applied.

[common disclaimer]


-----Original Message-----
From: Dunn, Toby [mailto: XXXX@XXXXX.COM ]
Sent: Wednesday, June 30, 2004 15:38
To: Groeneveld, Jim
Cc: SAS-L (E-mail)
Subject: RE: Macro Variable Problem


Jim,

I still disagree with you and we may very well have to leave it at that.

I see SAS code and the Macro language as being separate languages but
two that can work together.  Hence the reason you, me and others say
"macro language".  The Language part is what I believe is important.  By
denoting it as being a language separate from SAS open code; we
automatically segregate it off from the rest of the SAS language.
Therefore one can't say that a macro variable is comparable to a SAS
data set variable. It has to be thought of as and treated differently
than a SAS data set variable (the reason I believe that there is a lot
of confusion with beginners writing macro code).  Thus, in that light I
say that a macro variable can have a missing value.  Because of the fact
that a macro variable holds text values a " " is missing in macro land,
which is different that a missing text value in a variable that is in a
SAS dataset.

Hope this is clearer than my last email.

Toby Dunn

-----Original Message-----
From: Groeneveld, Jim [mailto: XXXX@XXXXX.COM ]
Sent: Wednesday, June 30, 2004 2:59 AM
To: Dunn, Toby
Cc: SAS-L (E-mail)
Subject: Re: Macro Variable Problem

Hi Toby,

Yes, of course a macro variable may be empty, but that does not mean
anything special in macro language, like missing values from datasets
are automatically treated specially (missing) in various statistical
PROCs. So, I would not call it missing, and certainly not in the sense
like a SAS dataset variable may be missing. It wrongly would suggest a
relation with SAS variables and a concept which does not exist. A macro
variable only contains text, which may be the absence of contents, with
a %length of zero. So I do stick to my statement that the concept of
missing values does not exist in macro language. I would only call the
absence of a value an empty value. But an empty value is being processed
just like any non-empty value. It often may be the initial value of a
list being built.

Regards - Jim.
.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .

Jim Groeneveld, MSc.
Biostatistician
Science Team
Vitatron B.V.
Meander 1051
6825 MJ  Arnhem
Tel: +31/0 26 376 7365
Fax: +31/0 26 376 7305
 XXXX@XXXXX.COM 
www.vitatron.com

Showing statistically significant differences between football teams,
generally all sporters, requires larger samples than usually applied.

[common disclaimer]


-----Original Message-----
From: Dunn, Toby [mailto: XXXX@XXXXX.COM ]
Sent: Tuesday, June 29, 2004 18:31
To: Groeneveld, Jim
Subject: RE: Re: Macro Variable Problem


Jim,

I was wondering about something you said, "The concept of missing values
does not exist in macro language."  I would have to say it does.
Take the simple case of "%let macvar = ;" the blank here is just missing
character data, nothing more nothing less.  So there is a concept of
missing data (whether it is intentionally left as blank or because of a
program design flaw).

Toby Dunn
[.........]

4. Picking a value from one variable based on values in another variable

5. Defining macro variable with another variable?

Hi,

  I have defined a variable called k in a do loop and then try to
create a macro out of it, but unable to do it.

%let proc_dt1 = 200507;
%let proc_dt2 = 200508;
%let proc_dt3 = 200509;
%let proc_dt4 = 200510;

%put &proc_dt1;
%put &proc_dt2;
%put &proc_dt3;
%put &proc_dt4;

%let proc_dt = proc_dt;
%put &proc_dt;

data _null_;
%put &proc_dt10;
do k = 1 to 4;
%let k = k;
%put &&proc_dt&k;
end;
run;

Can I assign a variable to create a macro variable? 

Thank you,
Papu.

6. Combine several variables to one variable (variable name + value)

7. Macro variable problem: year/month date value conversion

Hello all,

I would like to get a variable name "trx" changed to something like
"mic_200803" by running the following code.  But it failed.  Can you help?


------- code ------

%let endmo=1mar2008;
%macro test(dsn=);
data &dsn;
     sasdate=intnx('month',"endmo"d,0));
     call symput('yyyymm',put(sasdate,yymmn6.));
     set &dsn (rename=trx=&dsn._trx_&yyyymm);
run;
%mend;

%test(dsn=mic);

----- log ---------

MPRINT(RUNMARKET):  ;
SYMBOLGEN:  Macro variable DSN resolves to mic
MPRINT(RENAMEIT):   data mic;
SYMBOLGEN:  Macro variable ENDMO resolves to 01mar2008
MPRINT(RENAMEIT):   sasdate=intnx('month',"01mar2008"d,0);
MPRINT(RENAMEIT):   call symput('yyyymm',put(sasdate,yymmn6.));
SYMBOLGEN:  Macro variable DSN resolves to mic
WARNING: Apparent symbolic reference YYYYMM not resolved.




Susie Chung Li

8. Macro problem: need to dynamically create variables from values