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 1 | food | total price |
---|---|---|
name1 | orange | 1.5 |
name2 | onion | 2 |
name2 | bean | 2 |
name3 | potato | 2.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~
Possibly
if index("&itemlist",food) >0 then food_type=' xx';
might work
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.);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.