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

Below is my code and ouput.

 

I transposed "xy" dataset into  "final" dataset, then used proc report to output.

If anyone know a way to output the data directly from 'xy' datasets with proc report. Thanks.

 

 

 11.jpg

 

 /******CODE*****************************************/

/* Data part**/

data a;
trt="1"; output;
trt="2"; output;
trt="3"; output;
run;
data a;
trt="1"; output;
trt="2"; output;
trt="3"; output;
run;
data b;
event="a"; num=2; output;
event="b"; num=3; output;
event="c"; num=4; output;
run;

proc sql;
create table x as
select a.*, b.*
from a, b
order by b.event, a.trt;

create table y as
select event, sum(num) as total
from x
group by event;

create table xy as
select a.*, b.total, round(a.num/b.total*100,0.1) as per
from x as a, y as b
where a.event=b.event
order by event, trt;
quit;

/*Data part end*/

 

 

proc transpose data=xy out=xy_1 prefix=num;
by event;
id trt;
var num;
run;

 

proc transpose data=xy out=xy_2 prefix=per;
by event;
id trt;
var per;
run;

 

data final;
merge xy_1 xy_2;
by event;
drop _name_;
run;


ods rtf file= "C:\XXXXX\123.rtf";
proc report data=final;
column event ("trt1" (num1 per1)) ("trt2" (num2 per2)) ("trt3" (num3 per3));
define num:/display "n" center;
define per:/ display "%" center;
run;
ods rtf close;

 /****************************************/

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Without the transpose we could use the proc report on xy dataset to get the output as below, try

 

data xy_;
length trt1 $10.;
set xy;
trt1=cats('trt',trt);
run;

proc report data=xy_;
column event (trt1),(num per);
define event /group width=10;
define trt1 / ' ' across order=internal;
define num/ "n" center ;
define per/  "%" center;
run;

 

Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Without the transpose we could use the proc report on xy dataset to get the output as below, try

 

data xy_;
length trt1 $10.;
set xy;
trt1=cats('trt',trt);
run;

proc report data=xy_;
column event (trt1),(num per);
define event /group width=10;
define trt1 / ' ' across order=internal;
define num/ "n" center ;
define per/  "%" center;
run;

 

Thanks,
Jag
Niugg2010
Obsidian | Level 7

Thanks. It works.

Jagadishkatam
Amethyst | Level 16
Thanks,
Could I request you to please mark this answer correct, it will help everyone in the community to quickly point to the best answers.
Thanks,
Jag

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 706 views
  • 0 likes
  • 2 in conversation