BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhangda
Fluorite | Level 6

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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

3 REPLIES 3
BrunoMueller
SAS Super FREQ

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;

 

 

zhangda
Fluorite | Level 6

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!

 

BrunoMueller
SAS Super FREQ

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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