DATA Step, Macro, Functions and more

Multiple Bullet Points SAS Data Set

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Multiple Bullet Points SAS Data Set

Hi everyone,

 

I have the following dataset:

Product_ID Name
ID1 NAME1
ID1 NAME2
ID1 NAME3
ID2 NAME4
ID3 NAME5
ID3 NAME6
ID4 NAME7
ID5 NAME8
ID6 NAME9
ID7 NAME10


I'm trying to find a way to output/list the grouped Names for each Product ID in a dataset, like the table below:

 

Product_ID New Column
ID1 • NAME1
• NAME2
• NAME3
ID2 • NAME4
ID3 • NAME5
• NAME6
ID4 • NAME7
ID5 • NAME8
ID6 • NAME9
ID7 • NAME10

 

Do you have any suggestions how to achieve this?

 

 

Thank you!


Accepted Solutions
Solution
‎04-10-2017 08:48 AM
Super User
Super User
Posts: 7,392

Re: Multiple Bullet Points SAS Data Set

Hi,

 

This works (note you need ods excel which in one of the newer releases - 9.3 onwards perhaps, can't remember):

data x;
  infile cards dlm="," ;
  input product_ID : $20. NAME : $60. ;
  cards; 
ID1,NAME1
ID1,NAME2
ID1,NAME3
ID2,NAME4
ID3,NAME5
ID3,NAME6
ID4,NAME7
ID5,NAME8
ID6,NAME9
ID7,NAME10
; 
run;

data have;
length temp $ 1024; 
set x;
by product_id;
if first.product_id then temp='';
retain temp;
  temp = catx('0D'x, temp, catx(" ", "^{unicode 25cf}",NAME) );
if last.product_id then output;
run;

ods noresults;
ods escapechar="^"; 
ods excel file="s:\temp\rob\test.xlsx";
proc report data=have nowd OUT=have2  split="/";  
  column product_id temp;
  define product_id / display; 
  define temp / display style(column)=[protectspecialchars=off cellheight=3cm cellwidth=2cm]; 
run;
ods excel close;

View solution in original post


All Replies
Super User
Super User
Posts: 7,392

Re: Multiple Bullet Points SAS Data Set

Just an overview:

1) Add the bullet to your data (probably need to use the '07'x) e.g.:

data have;

  set have;

  name=cats('07'x,name);

run;

 

2) Use proc report to output your data, setting product_id as order variable and applying spanrows option:

proc report data=have spanrows;

  define product_id / order style(column)=[vjust=middle];

...

 

Contributor
Posts: 42

Re: Multiple Bullet Points SAS Data Set

Hi RW9,

 

Thank you for help!

 

I've adjusted some of the code that give me the correct output:

data x;
  infile cards dlm="," ;
  input product_ID : $20. NAME : $60. ;
  cards; 
ID1,NAME1
ID1,NAME2
ID1,NAME3
ID2,NAME4
ID3,NAME5
ID3,NAME6
ID4,NAME7
ID5,NAME8
ID6,NAME9
ID7,NAME10
; 
run;

data have;
length temp $ 1024; 
set x;
by product_id;
if first.product_id then temp='';
retain temp;
  temp = catx("^{newline}", temp, catx(" ", "^{unicode 25cf}",NAME) );
if last.product_id then output;
run;

ods escapechar="^"; 

proc report data=have nowd OUT=have2  split="/";  
  column product_id temp;
  define product_id / display; 
  define temp / display; 
run;

But now I'm struggling to export the ODS output to Excel, since the bullet points are now exported into different rows and not into one row, is there any way around this?

 

Thank you!

 

 

 

 

 

Solution
‎04-10-2017 08:48 AM
Super User
Super User
Posts: 7,392

Re: Multiple Bullet Points SAS Data Set

Hi,

 

This works (note you need ods excel which in one of the newer releases - 9.3 onwards perhaps, can't remember):

data x;
  infile cards dlm="," ;
  input product_ID : $20. NAME : $60. ;
  cards; 
ID1,NAME1
ID1,NAME2
ID1,NAME3
ID2,NAME4
ID3,NAME5
ID3,NAME6
ID4,NAME7
ID5,NAME8
ID6,NAME9
ID7,NAME10
; 
run;

data have;
length temp $ 1024; 
set x;
by product_id;
if first.product_id then temp='';
retain temp;
  temp = catx('0D'x, temp, catx(" ", "^{unicode 25cf}",NAME) );
if last.product_id then output;
run;

ods noresults;
ods escapechar="^"; 
ods excel file="s:\temp\rob\test.xlsx";
proc report data=have nowd OUT=have2  split="/";  
  column product_id temp;
  define product_id / display; 
  define temp / display style(column)=[protectspecialchars=off cellheight=3cm cellwidth=2cm]; 
run;
ods excel close;
Contributor
Posts: 42

Re: Multiple Bullet Points SAS Data Set

Thank you @RW9 - working perfectly!

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 255 views
  • 0 likes
  • 2 in conversation