Hello,
If I have an output table like this with millions of records, how do I use SAS to count Form A only, Form B only, Form C only and Multiform? I don’t want 102 and 104 to be counted as part of Form A only or Form C only. I want 102 & 104 to be in multiform.
Id | Age | FormA | FormB | FormC | Form_A_only | Form_B_only | Form_C_only | Multi-form |
101 | 10-20 | 1 | . | . | 1 | 0 | 0 | 0 |
102 | 10-20 | 1 | 0 | . | 1 | 1 | 0 | 1 |
103 | 21-30 | . | . | 0 | 0 | 0 | 1 | 0 |
104 | 10-20 | 1 | 0 | . | 1 | 0 | 1 | 1 |
105 | 21-30 | . | 1 | . | 0 | 1 | 0 | 0 |
106 | 10-20 | 1 | . | . | 1 | 0 | 0 | 0 |
107 | 21-30 | 1 | . | . | 1 |
|
|
|
When I used
proc freq data=have;
table form_A_only;
run;
102 and I04 was counted as part of it which I don’t want.
this is my output of interest
| Form A only | Form B only | Form C only | Multiple form |
Group |
|
|
|
|
10-20 years | 2 | 0 | 0 | 2 |
21-30 years | 1 | 1 | 1 | 0 |
You again are not defining what you mean by "Form A only".
And please separate what you have to start from what you want. If you can't provide a data step at least paste the "example" data as text, preferably in a text box opened on the forum with the </> icon above the message window.
Table layouts are quite often extremely hard or impossible to turn into data step code because of other formatting stuff that isn't visible.
If you mean that have a data set that start like this:
data have; input id age $ FormA FormB FormC; datalines; 101 10-20 1 . . 102 10-20 1 0 . 103 21-30 . . 0 104 10-20 1 0 . 105 21-30 . 1 . 106 10-20 1 . . 107 21-30 1 . . ;
Then
data need; set have; Form_A_only= not missing(formA); Form_B_only= not missing(formB); Form_C_only= not missing(formC); Multi_form = (n (FormA, FormB, Formc)>1); run; proc summary data=need nway; class age; var Form_A_only Form_B_only Form_C_only Multi_form; output out=want (drop=_:) sum=; run;
if you want a data set.
Or if by output you mean a report that people read:
Proc tabulate data=need; class age; var Form_A_only Form_B_only Form_C_only Multi_form; table age, (Form_A_only Form_B_only Form_C_only Multi_form)*sum=' ' ; run;
or
proc report data=need; columns age Form_A_only Form_B_only Form_C_only Multi_form; define age /group; run;
If I understand you correctly:
proc freq data=have;
where multiform=0;
table form_A_only;
run;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.