BookmarkSubscribeRSS Feed
Pinky9
Calcite | Level 5

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


2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Ksharp
Super User
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1098 views
  • 0 likes
  • 3 in conversation