0

Greetings SAS experts,

I have a lot of statements that will vary that are structured like this:

if item = '0123' then e123 = data1; if item = '0541' then r541 = data2;

the variable item contains character values that are numbers.

I have a lot of lines like the above and I wanted to write a macro inside of a data step that allows me to do something like this

%macro ifcondition(newitem);
if item = '&newitem' then E&newitem = data1; 
if item = '&newitem' then R&newitem = data2;
%mend;

%ifcondition(0123);

So I would like the numerous variants of this...

%ifcondition(0123);

to evaluate to this:

if item = '0123' then E0123 = data1; if item = '0123' then R0123 = data2;

What is the easiest way I can modify this so that this works correctly?

Thanks!!

Joe
  • 62,789
  • 6
  • 49
  • 67
user650738
  • 31
  • 1
  • 2
  • 5

1 Answers1

0

simply use double quotes, this worked for me:

data want;
input item $ try $ try2 $;
datalines;
0100 abcd aa
0101 pipp bb
0102 plut cc
2000 gian dd
2001 luca ee
2002 tryu ff
3007 troy gg
3156 boss hh
;

%macro ifcondition(newitem);
if item = "&newitem" then E&newitem. = try; 
if item = "&newitem" then R&newitem. = try2;
%mend;

data want1;
set want;
%ifcondition(0101);
%ifcondition(3007);
run;
stat
  • 699
  • 3
  • 10
  • Thank you so much. The solution was simple but worked fine. I was also able to use it to evaluate the way I wanted it to. – user650738 May 14 '15 at 22:36