Hi guys,
suppose to have the following table:
N Count Figure
100 28 Psicol
0 12 Psicol
50 6 Psicol
20 2 Psicol
80 2 Psicol
60 1 Psicol
0 29 Psy
100 10 Psy
50 5 Psy
20 3 Psy
80 2 Psy
10 1 Psy
70 1 Psy
Is there a way to format the table in this way?
Figure 0 10 20 30 40 50 60 70 80 90 100
Psicol 12 na 2 na na 6 1 na 2 na 28
Psy 29 1 3 na na 5 na 1 2 na 10
Thank you in advance
Please, @NewUsrStat from now on, provide data as working SAS data step code, as shown below.
data have;
input N Count Figure $;
cards;
100 28 Psicol
0 12 Psicol
50 6 Psicol
20 2 Psicol
80 2 Psicol
60 1 Psicol
0 29 Psy
100 10 Psy
50 5 Psy
20 3 Psy
80 2 Psy
10 1 Psy
70 1 Psy
;
proc report data=have;
columns figure count,n;
define figure/group "Figure";
define n/across order=internal ' ';
define count/sum " ";
run;
Please, @NewUsrStat from now on, provide data as working SAS data step code, as shown below.
data have;
input N Count Figure $;
cards;
100 28 Psicol
0 12 Psicol
50 6 Psicol
20 2 Psicol
80 2 Psicol
60 1 Psicol
0 29 Psy
100 10 Psy
50 5 Psy
20 3 Psy
80 2 Psy
10 1 Psy
70 1 Psy
;
proc report data=have;
columns figure count,n;
define figure/group "Figure";
define n/across order=internal ' ';
define count/sum " ";
run;
This is one way to create variables for missing N 30, 40, 90.
data have;
input N count figure $;
cards;
100 28 Psicol
0 12 Psicol
50 6 Psicol
20 2 Psicol
80 2 Psicol
60 1 Psicol
0 29 Psy
100 10 Psy
50 5 Psy
20 3 Psy
80 2 Psy
10 1 Psy
70 1 Psy
;;;;
run;
data frame;
do N = 0 to 100 by 10;
output;
end;
run;
data have2;
set frame have;
run;
proc print;
run;
proc transpose data=have2
out=want(where=(not missing(figure)) drop=_name_)
prefix=N_;
by figure;
var count;
id N;
run;
proc print;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.