Saturday, February 15, 2014

From Vegan to Hunter

I'm a fan of Siddhartha-esque journeys. In Siddhartha's case, he explored the entire spectrum of religion, from starving as an ascetic to engaging in high-stakes gambling, only to settle down on the river, in the literal and figurative middle.

The Mindful Carnivore: A Vegetarian's Hunt for Sustenance is same for food, as we watch the author, Tovar Cerulli, embrace veganism and then become a hunter over the course of many years.

For me, eating meat was always a cognitive dissonance. I like meat, eat if often, but am only occasionally reminded of its gruesome origins. We dote on our cat, Apollo, buying him endless toys, making sure to mentally stimulate him, paying someone to come check on him daily when we're out of town, and feeling guilty if we are out for dinner or drinks and miss his feeding schedule by a few hours. Imagine the horror that would occur in my household if I took out our sharpest knife from the kitchen, grabbed Apollo, and slit his throat. Sharon would instantly divorce me, and I might even end up in jail. Yet week after week, we bring home meat from the grocery store, dissociated from its former animal, "a gaping chasm between field and table," as Cerulli writes. Why are some animals endeared and others mindlessly eaten? This is a topic also covered in depth in the book Some We Love, Some We Hate, Some We Eat.

As an economist, I've never much bought into the categorical imperative: "Act only on that maxim through which you can at the same time will that it should become a universal law." Sure, maybe I could adopt a lifestyle that involves veganism or diligent recycling, but even if I do, the aggregate impact on the world is squat. In fact, I might be more easily persuaded to vote a citywide ban on plastic grocery bags than I would be to use reusable bags on my own, as the latter has so little impact. Thinking through the supply chain for food -- from farmer to wholesaler to stores and restaurants -- it's hard to prove that a lifetime of veganism would save even a single animal.

Cerulli also comes to the realization that being a vegan and growing his own food aren't harmless. This is a man who buys Christmas trees near power lines, figuring that they will be cut down anyway, and who has an ethical dilemma over killing an insect. Yet as he tried to grow his own food, he kept having his crops ravaged by gophers and deer. After failed attempts to quell the problem by capturing and relocating the gophers and building more elaborate fencing, he came to the realization that he needed to start shooting them with his BB gun. He then learned from others farmers about how many deer need to be killed to protect their crops. The growth of non-meat foods still involves plenty of indirect death. So he starts thinking about the cycle of life and death more deeply, a journey that progresses until he himself becomes a hunter in order to come face to face with the act of killing an animal for meat.

The resolution may come for one innovations that I'm most hoping for in the coming years: synethic meat. Hopefully someday, we can get the same taste, pleasure, and nutrition without the death.

One other loose end from the book that I found interesting: The campaigns for eating vegetables and curbing animal cruelty were initially totally separate. There were ads in the early 1900s about how vegetarian diets helped the University of Chicago football team play so well and be so manly.

Friday, February 14, 2014

Looping with SAS Macros

SAS macros can be used to loop through any list stored in a string of text and do a repetitive process on each element of the list. You can also create a list dynamically from an existing SAS dataset.

Step 1: Read in a list of states of abbreviations from an existing dataset

First, you need to create your list of elements. It can be as simple as listing them in a macro variable:

%let list = apple banana grape;

Or you can read them from an existing SAS dataset using "separated by." In this example, I am reading two lists: states and state abbreviations. Notice that I'm separating my state list by slashes, so that "Rhode" and "Island" won't look like two different elements when it comes time to loop. 

proc sql noprint;
select state, abbr into : full_list separated by "/", : abbr_list separated by " " from greg.states;
quit;

Step 2: Count the elements in the list

Now, I'm going to invoke a macro to count the number of elements in the list. Because both of my lists are the same number of elements, I only need to do this once. I start at 0, then increment by 1 each time I scan through the list and see another string of text separated by my delimiter (here, a slash).

%macro varcount;
%global var_num;
%let var_num=0;
%do %while(%qscan(&full_LIST,&var_num.+1,"/") ne %str());
%let var_num = %eval(&var_num+1);
%end;
%mend varcount;
%varcount

Step 3: Assign each element in to a numbered macro variable

Now, I am going to use the count I got above and loop through s times, from 1 to the maximum value. Each time I go through the loop, I'm going to define a numbered macro variable. The first full name will be "Alabama", stored in a macro variable called "full1". The first abbreviation will be "AL", stored in a macro variable called "abbr1". The repeats all the way through "full51" and "abbr51".

%macro numvars;
%do s =1 %to &var_num;
%global full&s. abbr&s.;
%let full&s. = %qscan(&full_LIST.,&s,"/");
%let abbr&s. = %qscan(&abbr_LIST.,&s," ");
%end;
%mend numvars;
%numvars

Step 4: Loop through each element

Here is where the magic starts to happen. I am again looping through s, from 1 to the number of elements that I have. Each time I'm in the loop and want to refer to a state, I should use &&full&s..

As SAS revolves macros, it turns two &'s into one, and turns single & into the macro variable name it finds up until a period.

Original: &&full&s..
First pass (when s = 1): &full1
Second pass (look for value of &full1): Alabama

Within the loop, you can put ANY TEXT, and it will be repeated for each element in the list. Here, I will get a case statement with 51 when clauses, one for each state. Notice that the macro is invoked below, in the proc sql step. You can do pieces of a step like I've done here, or you can have a full step, or 50 full steps. I could start with a step where I am making a data set using only the Alabama rows, and then I can do a ton of transformations on it, then repeat for each new step. The possibilities are endless!

%macro states;
%do s = 1 % to &var_num;
when "&&full&s.." then "&&abbr&s.."
%end;
%mend states;

Proc sql;
select case %states end as state_abbr from full_states;
Quit;