## How to use Criteria that is embedded in a table field to create flags

Solved
Super Contributor
Posts: 334

# How to use Criteria that is embedded in a table field to create flags

The situation is that there is a flow of data coming in. Within it is a criteria that needs to be used to create flags. So what is the easiest / efficient way to apply the criteria for that observation to the value of that observation? Just keep in mind the criteria values are not set and change (for various reasons) with new data. I thought there was a way to set a macro value with each loop of the dataset and use that to write dynamic flag code, but I could not figure out what I was missing.

Below is a simple example trying to illustrate what I am trying to do. I only got so far before hitting a wall. I know there is a way to do this it just not coming to me.

data temp;

infile cards dsd;

input criteria \$ value;

cards;

> 65, 44

> 65, 75

< 23, 45

< 23, 22

;

run;

%macro res(c,v);

%global flag;

%if &v &c %then %let flag = 1;

%mend res;

data temp2;

set temp;

call execute('%res('||criteria||','||value||')') ;

run;

Thanks for the help!

EJ

Accepted Solutions
Solution
‎07-25-2014 09:35 AM
Super User
Posts: 9,599

## Re: How to use Criteria that is embedded in a table field to create flags

Hi,

data temp;
infile cards dsd;
input criteria \$ value;
cards;
> 65, 44
> 65, 75
< 23, 45
< 23, 22
;
run;

data _null_;
set temp end=last;
if _n_=1 then call execute('data want;
set temp;
attrib result format=\$1.;');
call execute(' if value '||strip(criteria)||' then result="Y";');
if last then call execute('run;');
run;

All Replies
Solution
‎07-25-2014 09:35 AM
Super User
Posts: 9,599

## Re: How to use Criteria that is embedded in a table field to create flags

Hi,

data temp;
infile cards dsd;
input criteria \$ value;
cards;
> 65, 44
> 65, 75
< 23, 45
< 23, 22
;
run;

data _null_;
set temp end=last;
if _n_=1 then call execute('data want;
set temp;
attrib result format=\$1.;');
call execute(' if value '||strip(criteria)||' then result="Y";');
if last then call execute('run;');
run;

Super Contributor
Posts: 334

## Re: How to use Criteria that is embedded in a table field to create flags

Thanks ... the whole trying to use the macro sent me down the wrong path! I just needed to have call execute construct the entire data step I needed.

Thanks again!

EJ

Super User
Posts: 10,787

## Re: How to use Criteria that is embedded in a table field to create flags

Hi, You gotta love RESOLVE. :smileylaugh:

```data temp;
infile cards dsd;
input criteria \$ value;
cards;
> 65, 44
> 65, 75
< 23, 45
< 23, 22
;
run;

data want;
set temp;
flag=resolve(cats('%eval(',value,criteria,')'));
run;

```

Xia Keshan

Posts: 3,852

## Re: How to use Criteria that is embedded in a table field to create flags

Keep in mind that the value returned from RESOLVE is character.

Super User
Posts: 10,787