BookmarkSubscribeRSS Feed
srinivaschary
Calcite | Level 5

Hi,

My data is like below i need to compare last month and current month data and need to highlight with up arrow or down arrow for growth or loss please provide the code thanks in advance

 

data input

MonthLocationStores
11/1/2018Chennai16
11/1/2018Hyderabad12
11/1/2018Chennai14
11/1/2018Chennai12
11/1/2018Hyderabad32
11/1/2018Hyderabad14
12/1/2018Chennai17
12/1/2018Hyderabad16
12/1/2018Chennai1
12/1/2018Chennai21
12/1/2018Hyderabad12
12/1/2018Hyderabad12

 

Expected output:

attached image file

 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not here to type in test data, so just some example code - untested:

proc sort data=have;
  by location month;
run;
proc means data=have;
  var stores;
  by location month;
  output out=inter sum=want;
run;
proc transpose data=inter out=want;
  by location month;
  var want;
  idlabel month;
run;
data want;
  length col $2;
  set want;
  array var{2};
  if var{2} < var{1} then col=cats("^s={font_weight=bold font_color=red}↓ ^s={font_weight=normal font_color=black}",put(var{2},best.));
  else if var{2} > var{1} then col=cats("^s={font_weight=bold font_color=green}↑ ^s={font_weight=normal font_color=black}",put(var{2},best.));
  else col=strip(put(var{2},best.));
run;
ods escapechar="^";
proc report data=want;
  columns _all_;
run;

srinivaschary
Calcite | Level 5

Hi While am using that code showing below error.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You will need to get the special character to the output somehow, as you are not using a unicode system (and why not?) then you would need to push the symbol out some other way, maybe:

proc sort data=have;
  by location month;
run;
proc means data=have;
  var stores;
  by location month;
  output out=inter sum=want;
run;
proc transpose data=inter out=want;
  by location month;
  var want;
  idlabel month;
run;
data want;
  length col $2;
  set want;
  array var{2};
  if var{2} < var{1} then col=cats("^s={font_weight=bold font_color=red}^{unicode 28A9} ^s={font_weight=normal font_color=black}",put(var{2},best.));
  else if var{2} > var{1} then col=cats("^s={font_weight=bold font_color=green}^{unicode 26A9} ^s={font_weight=normal font_color=black}",put(var{2},best.));
  else col=strip(put(var{2},best.));
run;
ods escapechar="^";
proc report data=want;
  columns _all_;
run;

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!

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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