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 :
respid | status | S7_1 | S7_2 | S7_3 | S7_4 |
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 |
Table :
Age | Freq |
Base | 20 |
Less than 1 | 0 |
1 | 0 |
2 | 1 |
3 | 0 |
4 | 1 |
5 | 0 |
6 | 2 |
7 | 0 |
8 | 1 |
9 | 6 |
10 | 9 |
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;
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.