increment

Reply
Contributor
Posts: 35

increment

Hi All,

The data has 25 variables of S7 . It represents the age of children.

In data sheet, S7_1 S7_2 ...... and so on represents age of children.

here , first respondent has one child of age 18 and so on .

In table sheet , Total is not "no of respondents" but summing the frequency .

I am looking for table in sheet "tables" which gives increment base  as well as count for each interval.

Thanks in advance...

Data :

respidstatusS7_1S7_2S7_3S7_4
8complete10
21complete109
54complete42
67complete109
75complete109
93complete108
111complete109
134complete1096
169complete109610

Table :

AgeFreq
Base20
Less than 10
10
21
30
41
50
62
70
81
96
109


Super User
Super User
Posts: 7,392

Re: increment

Hi,

If you manipulate your data slightly then its simply a case of counting:

data have;
  attrib respid format=best. status format=$20. S7_1 S7_2 S7_3 S7_4 format=best.;
  infile datalines delimiter=" " missover;
  input respid status $ s7_1 s7_2 s7_3 s7_4;
datalines;
8 complete 10   
21 complete 10 9  
54 complete 4 2  
67 complete 10 9  
75 complete 10 9  
93 complete 10 8  
111 complete 10 9  
134 complete 10 9 6 
169 complete 10 9 6 10
;
run;

proc transpose data=have out=inter;
  by respid;
  var s7_1 s7_2 s7_3 s7_4;
run;

proc sql;
  create table WANT as
  select  distinct
          COL1 as AGE,
          count(RESPID) as FREQ
  from    (select * from WORK.INTER where COL1 ne .)
  group by COL1;
quit;

Super User
Posts: 9,662

Re: increment

data have;
  attrib respid format=best. status format=$20. S7_1 S7_2 S7_3 S7_4 format=best.;
  infile datalines delimiter=" " missover;
  input respid status $ s7_1 s7_2 s7_3 s7_4;
datalines;
8 complete 10    
21 complete 10 9   
54 complete 4 2   
67 complete 10 9   
75 complete 10 9   
93 complete 10 8   
111 complete 10 9   
134 complete 10 9 6  
169 complete 10 9 6 10 
;
run;
data temp;
 set have;
 length age $ 8;
 array a{*} s7: ;
 do i=1 to dim(a);
  if not missing(a{i}) then do;age=strip(a{i}); output; end;
 end;
 keep age;
run;
proc sql;
 create table want as
  select ' Base' as age,(select count(age) from temp) as Freq from temp(obs=1)
   union
  select ' Less Than 1' as age,(select count(age) from temp where input(age,best8.) lt 1) as Freq from temp(obs=1)
   union
  select age,count(age) as Freq from temp group by age;
quit;



Xia Keshan

Ask a Question
Discussion stats
  • 2 replies
  • 307 views
  • 0 likes
  • 3 in conversation