BookmarkSubscribeRSS Feed
Lulus
Obsidian | Level 7

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~

3 REPLIES 3
Reeza
Super User

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

You need to provide more detail otherwise.

See here:

ballardw
Super User

Possibly

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

might work

Tom
Super User Tom
Super User

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.);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 916 views
  • 0 likes
  • 4 in conversation