BookmarkSubscribeRSS Feed
santhosh
Fluorite | Level 6


i have a dataset

sno name m1 m2 s1 s2 e1 e1

1 A 20 30 25 45 26 27

1 B 25 32 55 20 41 25

1 C 27 40 28 44 46 37

1 D 29 50 35 42 36 42

i want output as

______________________________________________________________

|                   |          maths         |     Science             |     English             |

|SNo    name |  maths1| maths2  |science1 | science2  | english1|  english2|

|                    |           (1)           |           (2)                |         (3)                |

-------------------------------------------------------------------------------------------------------------

|1         A           20          30              25           45           26       27          |

|1         B           25          32             55           20           41        25          |

|1         C           27          40             28           44           46       37           |

|1         D           29          50             35           42           36          42        |

-------------------------------------------------------------------------------------------------------------

i want 1st level header as (1) (2) (3)

2nd level header as  maths1  maths2  |science1   science2  | english1   english2

3rd level headers as maths              Science                  English           

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a split char:

proc report split="~"...   /* Note the split=, you can put any character within the quotes */

     column ....;

     define sno / "SNo";

     define name / "Name";

     define m1/ "maths~maths1|maths2~(1)";   /* Note the tilde which indicates to line break */

     define m2 / "Science~science1|science2~(2)";

...

Jagadishkatam
Amethyst | Level 16

Please try

data have;

input

sno name $ m1 m2 s1 s2 e1 e1;

cards;

1 A 20 30 25 45 26 27

1 B 25 32 55 20 41 25

1 C 27 40 28 44 46 37

1 D 29 50 35 42 36 42

;

run;

ods rtf file='~\new.rtf';

proc report data = have nowindows headline headskip split='/' style(header)={just=c};

column ('Sno' sno) ('Name' name) ("Maths/Maths1|Maths2/(1)"  m1 m2 ) (  "science/science1|science2/(2)" s1 s2)  ( "english/english|english/(3)" e1 e2);

define sno / '';

define name / '';

define m1 / '';

define m2 / '';

define s1 / '';

define s2 / '';

define e1 / '';

define e2 / '';

run;

ods rtf close;

Thanks,

Jag

Thanks,
Jag
santhosh
Fluorite | Level 6

i want output as

______________________________________________________________

|                   |          maths         |     Science             |     English             |

|------------------------------------------------------------------------------------------------------------|

|SNo    name |  maths1| maths2  |science1 | science2  | english1|  english2 |

|------------------------------------------------------------------------------------------------------------|

|                   |           (1)            |           (2)                |         (3)                 |

|------------------------------------------------------------------------------------------------------------|

|1         A           20          30              25           45           26       27          |

|1         B           25          32             55           20           41        25          |

|1         C           27          40             28           44           46       37           |

|1         D           29          50             35           42           36          42        |

-------------------------------------------------------------------------------------------------------------

This is tablar format

1st heading above colunm will be (1) (2) (3)

above it seperate cels for Above M1 Maths1 and above M2 Maths2 so on

and above it maths science and englesh

i used | on to distingulish cells

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As far as I am aware you cant have "across" labels, which is what the maths, science, and (1) (2), over *and* under other labels, only above column labels.  Then point being that information applies to all deceding column headers.  You could however fake it pretty easily:

data have;

input

sno name $ m1 m2 s1 s2 e1 e2;

cards;

1 A 20 30 25 45 26 27

1 B 25 32 55 20 41 25

1 C 27 40 28 44 46 37

1 D 29 50 35 42 36 42

;

run;

data inter (keep=sno name m s e);

  set have;

  length m s e $25;

  m=put(m1,2.)||right(put(m2,16.));

  s=put(s1,2.)||right(put(s2,16.));

  e=put(e1,2.)||right(put(e2,16.));

run;

ods pdf file="s:\temp\rob.pdf" style=statistical;

proc report data=inter split="~" nowd;

  column (' ' sno name) ('maths' m) ('science' s) ('english' e);

  define sno / "SNo" style(header)=[just=l];

  define name / "name" style(header)=[just=r];

  define m / "maths1|maths2~(1)" style(header)=[just=c];

  define s / "science1|science2~(2)" style(header)=[just=c];

  define e / "english1|english2~(3)" style(header)=[just=c];

run;

ods _all_ close;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1215 views
  • 0 likes
  • 3 in conversation