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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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