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

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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;

View solution in original post

6 REPLIES 6
AncaTilea
Pyrite | Level 9

Hi,

Could you add in your output data set what exactly are you looking for?

Would you like the '?' to be filled??

Smiley Happy

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

michtka
Fluorite | Level 6

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.

AncaTilea
Pyrite | Level 9

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;

michtka
Fluorite | Level 6

Many thanks Anca tilea for your help.

data_null__
Jade | Level 19

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;

michtka
Fluorite | Level 6

Thanks data_null_, it was like I wanted.

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!

What is Bayesian Analysis?

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.

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
  • 6 replies
  • 868 views
  • 4 likes
  • 3 in conversation