Hi all, I am trying to run this code, and the idea is adding the rest of frequencies that
are not appearing in my final output *.
I try with completypes but it does not work for this example.
Any help?
data new;
input freq count treat;
datalines;
1 2 1
3 4 1
4 2 1
6 3 1
20 1 1
1 2 2
4 3 2
8 4 2
21 2 2
;
run;
proc sort data=new out=news; by freq; run;
proc transpose data=news out=newt (drop=_name_);
by freq;
id treat;
var count;
run;
proc summary data=newt nway completetypes;
class freq;
output out=want (drop=_type_ _freq_) idgroup(out(_1 _2)=);
run;
proc print data=want; run;
*output:
Obs freq _1 _2
1 1 2 2
2 3 4 .
3 4 2 3
4 6 3 .
5 8 . 4
6 20 1 .
7 21 . 2
Thanks,
V
Completetypes can only work with existing levels. If you want to add levels that do not exisit in the data you have to make them. CLASSDATA is one way to do that.
data new;
input freq count treat;
datalines;
1 2 1
3 4 1
4 2 1
6 3 1
20 1 1
1 2 2
4 3 2
8 4 2
21 2 2
;;;;
run;
proc summary;
output out=mm(drop=_:) min(freq)=min max(freq)=max;
run;
data classdata;
set mm;
do freq = min to max;
output;
end;
stop;
run;
proc summary data=new classdata=classdata nway;
by treat;
class freq;
freq count;
output out=filled(drop=_type_ rename=(_freq_=count));
run;
Hi,
Could you add in your output data set what exactly are you looking for?
Would you like the '?' to be filled??
Obs freq _1 _2
1 1 2 2
2 3 4 ?
3 4 2 3
4 6 3 ?
5 8 ? 4
6 20 1 ?
7 21 ? 2
freq (2nd column) I want to add: 2, 5, 7, 9, 10 , 11, 12, 13, 14, 15, 16, 17, 18, 19 ...but not manually, I would like to add in general the freqs that have missing values for both treatments _1 and _2.
Thanks.
How about this?;
%macro insert();
%do i = 1 %to 19;
data tmp_&i.;
set newt(obs = 1) ;
by freq;
drop _1 _2;
if first.freq then do;
freq = &i.;
output;
end;
run;
%end;
%mend insert;
%insert();
data final;
merge newt tmp_:;
by freq;
run;
Let me know if this is what you wanted;
Many thanks Anca tilea for your help.
Completetypes can only work with existing levels. If you want to add levels that do not exisit in the data you have to make them. CLASSDATA is one way to do that.
data new;
input freq count treat;
datalines;
1 2 1
3 4 1
4 2 1
6 3 1
20 1 1
1 2 2
4 3 2
8 4 2
21 2 2
;;;;
run;
proc summary;
output out=mm(drop=_:) min(freq)=min max(freq)=max;
run;
data classdata;
set mm;
do freq = min to max;
output;
end;
stop;
run;
proc summary data=new classdata=classdata nway;
by treat;
class freq;
freq count;
output out=filled(drop=_type_ rename=(_freq_=count));
run;
Thanks data_null_, it was like I wanted.
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.