I am currently analyzing marginal effect of stage and depression to inpatient costs using Generalized liner model gamma distribution and log link function, but I have encountered some problems.
I saw the SAS sample 63038 EXAMPLE 5: Marginal effect in a log-linked gamma model and also tried to use lsmeans and estimate to make marginal effect, but there has something wrong with my code . Could anyone kindly let me know how to fix this? Thank you very much.
Here is my SAS code:
%Margins(data = lifdat, class = stage, response = impatient costs, dist = gamma, model = impatient costs depression stage, margins = depression stage, options = cl)
proc genmod data=lifdat;
class depression (ref='0') stage (ref='4');
model y = depression age_group / dist=gamma link=log;
lsmeans depression / ilink cl;
lsmeans stage / ilink cl;
run;
proc genmod data=lifdat;
class depression (ref='0') stage (ref='4');
model y = depression stage / dist=gamma link=log;
estimate 'AME of depression' depression 1 / exp cl;
estimate 'AME of stage 1 vs 4' stage 1 0 0 -1 0 0 0 / exp cl;
estimate 'AME of stage 2 vs 4' stage 0 1 0 -1 0 0 0 / exp cl;
estimate 'AME of stage 3 vs 4' stage 0 0 1 -1 0 0 0 / exp cl;
estimate 'AME of stage 5 vs 4' stage 0 0 0 1 -1 0 0 / exp cl;
estimate 'AME of stage 6 vs 4' stage 0 0 0 0 1 -1 0 / exp cl;
estimate 'AME of stage 7 vs 4' stage 0 0 0 0 0 1 -1 / exp cl;
run;
@Heart_telling wrote:
... stuff deleted ...
, but there has something wrong with my code . Could anyone kindly let me know how to fix this? Thank you very much.
You provided your program code, but you gave us no clue as to how you know something is wrong. For instance, please provide:
BTW, you don't show a %MEND statement ending the macro definition, and you don't show code actually calling the macro.
Help us help you.
Did you download the %margins macro and store it on your computer and then include it in your program?
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.