How to code a macro like this?

Accepted Solution Solved
Reply
Contributor
Posts: 74
Accepted Solution

How to code a macro like this?

Hello, 

I am coding to generate a macro for the ods text part, see code below, for the part "item '83% of total with a score of 700 or greater , up 40 BPS compared to last year", I want to macro 83% and 40, which is when mid=d_2015 then I put exp there, which is 83% then,  exp-resp=40BPS, from which I take 40 and put into the ods text content. Would you please help me coding it out? Thanks!

 

data ds1;
input year $ mid $ resp exp rev;
datalines;
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.43 0.83 0.47
;
run;

 

proc odstext;
list / style=[color=darkgrey fontsize=2 font_weight=bold ];

item '83% of total with a score of 700 or greater , up 40 BPS compared to last year';
;
end;
run;

 

 


Accepted Solutions
Solution
‎11-10-2016 04:25 PM
SAS Super FREQ
Posts: 706

Re: How to code a macro like this?

You can calculated the difference between a value from the current onservation and the value of a previous observation using the DIF or LAG functions. To format a percentage value you can make use of the PUT function together with the PERCENT. format. The CAT... family of functions allow you to concatenate char values together. Find below a sample program that illustrates the use of these functions. This should help you to get the desired result.

 

data ds1;
input year $ mid $ resp exp rev;
datalines;
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.43 0.83 0.47
; 

proc sort data=ds1;
  by year mid;
run;

data want;
  set ds1;
  diff_resp = dif1(resp);
  length text $ 256;
  text = catx(" "
    , put(resp, percent9.)
    , "of total of score with 700 or greater, up"
    , diff_resp * 100 
    , "BPS compared to last year"
  );
run;

Bruno

View solution in original post


All Replies
SAS Super FREQ
Posts: 706

Re: How to code a macro like this?

You can build the text to display and write the proper ITEM statements into a file, this can then be %INCLUDE at the proper location in your code. See sample below.

filename items temp;
data ds1;
input year $ mid $ resp exp rev;
line = catx("*", year, mid, resp, exp, rev);
stmt = catx(" ", "item", quote(strip(line)), ";");
file items;
put stmt;
datalines;
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.43 0.83 0.47
;
run;

 

proc odstext;
list / style=[color=darkgrey fontsize=2 font_weight=bold ];
%include items / source2;
end;
run;

 

 

Contributor
Posts: 74

Re: How to code a macro like this?

Hi Bruno,

 

Would you please suggest me how to macro the difference between the numbers, which changes very month for example, from the table below, I can get three columns, resp, exp, and rev, the macro named difference is rev minus resp when mid=s_700,  thanks a lot!

 

Solution
‎11-10-2016 04:25 PM
SAS Super FREQ
Posts: 706

Re: How to code a macro like this?

You can calculated the difference between a value from the current onservation and the value of a previous observation using the DIF or LAG functions. To format a percentage value you can make use of the PUT function together with the PERCENT. format. The CAT... family of functions allow you to concatenate char values together. Find below a sample program that illustrates the use of these functions. This should help you to get the desired result.

 

data ds1;
input year $ mid $ resp exp rev;
datalines;
s_700 d_2016 0.83 0.83 0.47
s_700 d_2015 0.43 0.83 0.47
; 

proc sort data=ds1;
  by year mid;
run;

data want;
  set ds1;
  diff_resp = dif1(resp);
  length text $ 256;
  text = catx(" "
    , put(resp, percent9.)
    , "of total of score with 700 or greater, up"
    , diff_resp * 100 
    , "BPS compared to last year"
  );
run;

Bruno

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 218 views
  • 0 likes
  • 2 in conversation