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;
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
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;
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!
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.