How to modify MACRO to display MEDIAN?

Reply
Occasional Contributor
Posts: 6

How to modify MACRO to display MEDIAN?

I am having some difficulty fixing this macro code>

 

libname mylib 'C:\Users\Daddy\Documents';
%include 'C:\Users\Daddy\Desktop\face.sas';
%face (group,sbpbl sbp12 cholbl chol12 hdlbl hdl12 glucosbl glucos12,data=tomhs);
run;


%macro face (group,sbpbl, sbp12, cholbl, chol12, hdlbl, hdl12, glucosbl, glucos12,data=tomhs,dec=3,all=all);
%do I = 1%to902;
%let depvar = %scan(&sbpbl sbp12 cholbl chol12 hdlbl hdl12 glucosbl glucos12,&i);
%let%length (&depvar) = 0 %goto done;
 proc tabulate data=&tomhs noseps;
  class &group; sbpbl&depvar;
  table (&group &all), (&depvar)*(n*f=7.0 mean*f=7.&dec std*f=7.&dec
                                min*f=7.&dec max*f=7.&dec med*f=7.&dec)/rts=30;
 run;
%end;
 %done:
%mend face;
libname mylib'C:\Users\Daddy\Documents';

%include 'C:\Users\Daddy\Desktop\face.sas'
%face (group,sbpbl sbp12 cholbl chol12 hdlbl hdl12 glucosbl glucos12, data=tomhs);
run;

Please how do I modify this macro code to display MEDIAN? Thanks

Super User
Posts: 6,008

Re: How to modify MACRO to display MEDIAN?

Posted in reply to arrytanny

Are you claiming that this code works as intended, except that it fails to print the median?  That would be a surprise.

 

Perhaps  you could post the original macro, before you started playing with it.  There are many issues to fix here.

Occasional Contributor
Posts: 6

Re: How to modify MACRO to display MEDIAN?

Posted in reply to Astounding

The first part runs,

afterwards the remaining part never works. It gives several error that I can not fathom.

Super User
Posts: 6,008

Re: How to modify MACRO to display MEDIAN?

Posted in reply to arrytanny

If the first part runs, then post the contents of C:\Users\Daddy\Desktop\face.sas

 

It may not print the median, but as long as it is working it can be tweaked to add the median to the report.

Occasional Contributor
Posts: 6

Re: How to modify MACRO to display MEDIAN?

Posted in reply to Astounding

Si it fails to give an output that included MEDIAN

Super User
Posts: 12,148

Re: How to modify MACRO to display MEDIAN?

Posted in reply to arrytanny

Hint:  Set options mprint symbolgen mlogic;

Run your code;

Paste the generated statements and error messages from the log into a code box.

Super User
Posts: 21,546

Re: How to modify MACRO to display MEDIAN?

Posted in reply to arrytanny

Mistakes from a quick scan

 

  1. SCAN Is being used incorrectly
  2. Macro is called before it’s declared 
  3. Multiple %include for same program
  4. Incorrect use of DATA parameter -> this is a big one. Everything will be wrong if this isn’t done correctly because you’re not pointing at the data you think you are. 
  5. I don’t think GOTO does what you think it’s doing

 

Oddly, the median part is actually correct....

 


arrytanny wrote:

I am having some difficulty fixing this macro code>

 

libname mylib 'C:\Users\Daddy\Documents';
%include 'C:\Users\Daddy\Desktop\face.sas';
%face (group,sbpbl sbp12 cholbl chol12 hdlbl hdl12 glucosbl glucos12,data=tomhs);
run;


%macro face (group,sbpbl, sbp12, cholbl, chol12, hdlbl, hdl12, glucosbl, glucos12,data=tomhs,dec=3,all=all);
%do I = 1%to902;
%let depvar = %scan(&sbpbl sbp12 cholbl chol12 hdlbl hdl12 glucosbl glucos12,&i);
%let%length (&depvar) = 0 %goto done;
 proc tabulate data=&tomhs noseps;
  class &group; sbpbl&depvar;
  table (&group &all), (&depvar)*(n*f=7.0 mean*f=7.&dec std*f=7.&dec
                                min*f=7.&dec max*f=7.&dec med*f=7.&dec)/rts=30;
 run;
%end;
 %done:
%mend face;
libname mylib'C:\Users\Daddy\Documents';

%include 'C:\Users\Daddy\Desktop\face.sas'
%face (group,sbpbl sbp12 cholbl chol12 hdlbl hdl12 glucosbl glucos12, data=tomhs);
run;

Please how do I modify this macro code to display MEDIAN? Thanks


 

SAS Super FREQ
Posts: 9,039

Re: How to modify MACRO to display MEDIAN?

[ Edited ]

Hi:
In ;your TABLE statement, you have specified many statistics correctly -- for example, N, MEAN, STD, MIN, and MAX. However, you have this
med*f=7.&dec

in your TABLE statement and the correct specification for the MEDIAN statistic is either MEDIAN or P50, as shown in the documentation.
http://go.documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=p0n4welprckk8yn1ro9swa...

 

  Look what happens when I try the "MED" statistic as a keyword in TABULATE:

tab_stats.png


Cynthia

Ask a Question
Discussion stats
  • 7 replies
  • 125 views
  • 0 likes
  • 5 in conversation