BookmarkSubscribeRSS Feed
arrytanny
Calcite | Level 5

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

7 REPLIES 7
Astounding
PROC Star

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.

arrytanny
Calcite | Level 5

The first part runs,

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

Astounding
PROC Star

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.

arrytanny
Calcite | Level 5

Si it fails to give an output that included MEDIAN

ballardw
Super User

Hint:  Set options mprint symbolgen mlogic;

Run your code;

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

Reeza
Super User

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


 

Cynthia_sas
Diamond | Level 26

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1691 views
  • 0 likes
  • 5 in conversation