BookmarkSubscribeRSS Feed
Heart_telling
Calcite | Level 5

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;

 

 

 





2 REPLIES 2
mkeintz
PROC Star

@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:

 

  1. A copy of the sas log, with any notes or errors messages.

  2. A description of what your code produced, versus what you expected.

 

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PaigeMiller
Diamond | Level 26

Did you download the %margins macro and store it on your computer and then include it in your program?

--
Paige Miller

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 576 views
  • 0 likes
  • 3 in conversation