Discussion:
Macro and proc sql case statement
(too old to reply)
s***@gmail.com
2007-06-01 16:21:24 UTC
Permalink
Dear SAS Gurus,

I need some help here.

i have a proc sql as follows,


%let imp = a;

proc sql;
create table temp as
select case when &imp = a then x + 1
else x
end as y
from temp1;
quit;

my question here is I have this whole code in a macro. Some times the
imp variable resolves to a some times not.

when it resolves to a it is not working. It says a variable does not
exist.

what should i modify in proc sql to make it work.

thanks
toby dunn
2007-06-01 16:37:19 UTC
Permalink
If &Imp is refering to a variable then do:

UpCase( &imp ) = 'A'


Else If &Imp is refering to the value 'a' then do:

%UpCase( "&IMP" ) = "A"





Toby Dunn

If anything simply cannot go wrong, it will anyway. Murphys Law #2.

The buddy system is essential to your survival; it gives the enemy somebody
else to shoot at.
Murphys Law #


Tell a man there are 300 billion stars in the universe and he'll believe
you. Tell him a bench has wet paint on it and he'll have to touch to be
sure. Murphys Law #9






From: ***@GMAIL.COM
Reply-To: ***@GMAIL.COM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Macro and proc sql case statement
Date: Fri, 1 Jun 2007 09:21:24 -0700

Dear SAS Gurus,

I need some help here.

i have a proc sql as follows,


%let imp = a;

proc sql;
create table temp as
select case when &imp = a then x + 1
else x
end as y
from temp1;
quit;

my question here is I have this whole code in a macro. Some times the
imp variable resolves to a some times not.

when it resolves to a it is not working. It says a variable does not
exist.

what should i modify in proc sql to make it work.

thanks

_________________________________________________________________
Get a preview of Live Earth, the hottest event this summer - only on MSN
http://liveearth.msn.com?source=msntaglineliveearthhm
Pardee, Roy
2007-06-01 16:41:10 UTC
Permalink
At runtime that should resolve to:

... Case when a = a then x + 1

So SAS will look for a field called 'a' in your temp1 table.

To use the 'a' there as a text literal instead of a var reference,
you've got to throw some quotes around it--e.g.:

select case when "&imp" = "a" then x + 1
else x

HTH,

-Roy

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@GMAIL.COM
Sent: Friday, June 01, 2007 9:21 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Macro and proc sql case statement

Dear SAS Gurus,

I need some help here.

i have a proc sql as follows,


%let imp = a;

proc sql;
create table temp as
select case when &imp = a then x + 1
else x
end as y
from temp1;
quit;

my question here is I have this whole code in a macro. Some times the
imp variable resolves to a some times not.

when it resolves to a it is not working. It says a variable does not
exist.

what should i modify in proc sql to make it work.

thanks
Jake Bee
2007-06-01 16:45:44 UTC
Permalink
Can't really figure out what you're trying to do here. Perhaps others in
the group will understand the question. But attached is some code that may
either answer your question, or
help you to refine the question.

data temp1;
x=1; imp='a'; output;
x=2; imp='a'; output;
x=3; imp='b'; output;
run;


%macro test(imp);

%let varin=%sysfunc(upcase(&imp));

proc sql feedback undo_policy=none;
create table temp as
select x, case upcase(imp)
when "&varin" then x + 1
else x
end as y
from temp1;
quit;

%mend test;

%test(a);
Post by s***@gmail.com
Dear SAS Gurus,
I need some help here.
i have a proc sql as follows,
%let imp = a;
proc sql;
create table temp as
select case when &imp = a then x + 1
else x
end as y
from temp1;
quit;
my question here is I have this whole code in a macro. Some times the
imp variable resolves to a some times not.
when it resolves to a it is not working. It says a variable does not
exist.
what should i modify in proc sql to make it work.
thanks
Loading...