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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.