DATA Step, Macro, Functions and more

data step question: to tell if a term is belonged to a term_group

Reply
Contributor
Posts: 46

data step question: to tell if a term is belonged to a term_group

I am trying to do this to match an item (apple, green_onion, yam, orange...... ) with its own catgory.

Priror to it, I have tables that lists items in each group.

The two resouce tables are:

Vegie_table with two columns: item(50+)  group (all values='vegie')

Fruit_table with two columns: items(50+)  group(all values='frt')

drink_table with two columns: items(1000+)  group(all values='drk')

My table look like this

Header 1foodtotal price
name1orange1.5
name2onion2
name2bean2
name3potato2.8

I would like to create another column ----- food_type which indicates the type of the name in the food column.

I tried to use

if food is in (&itemlist.) then food_type='  xx ;

where itemlist is combined by vegie_table and fruit_table

but the itemlist I obtained has no quotes seperate them so I can not do it this way. Imagine I need to do this with my drink_list as well.

this is probaaly like SAS version of vlookup....

Please let me know how to do it with what I want.   Thank you all~

Super User
Posts: 19,850

Re: data step question: to tell if a term is belonged to a term_group

If its a version of vlookup, look at proc format and put statements or merges.

You need to provide more detail otherwise.

See here:

Super User
Posts: 11,343

Re: data step question: to tell if a term is belonged to a term_group

Possibly

if index("&itemlist",food) >0 then food_type=' xx';

might work

Super User
Super User
Posts: 7,070

Re: data step question: to tell if a term is belonged to a term_group

You should be able to convert your lookup tables into a format.

I would combine the three tables into one and use it as the CNTLIN

Vegie_table with two columns: item(50+)  group (all values='vegie')

Fruit_table with two columns: items(50+)  group(all values='frt')

drink_table with two columns: items(1000+)  group(all values='drk')

data formats ;

  set vegie_table fruit_table drink_table ;

  by item;

  retain fmtname 'FOOD' type 'C' ;

  rename item=start group=label;

run;

proc format cntlin=formats;

run;

....

food_type = put(food,$food.);

Ask a Question
Discussion stats
  • 3 replies
  • 198 views
  • 0 likes
  • 4 in conversation