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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.