DATA Step, Macro, Functions and more

Crosstables with arrays / several conditions

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Crosstables with arrays / several conditions

Dear SAS users,

I want to make a Crosstable with a character variable called fab and a set of variables, for which I made an array. The variables in the array all contain names with the chain icd_nd* where star is a number from 1 to 89.

The crosstable should contain only observations where the condition of another variable, which is a dummy, having the value 1 is fulfilled (gdrg = 1). Another condition should be that that only a set of approximately 30 values, which appear in icd_nd* should be accounted for in the crosstab. For example, I want to look whether the value "test" is in all icd_nd* and crosstab it with fab. Then I want to look if "test1" is in icd_nd* and crosstab it, independent whether "test" is in icd_nd*.

So I have two conditions, gdrg=1 and whether a set of values is in icd_nd*. I could use "where (gdrg =1);" for the first condition, but I dont know if the solution for the latter problem would have an impact on this syntax. Can you help me with the solution for my latter problem?

Best,

Dennis


Accepted Solutions
Solution
‎04-01-2013 10:26 PM
Respected Advisor
Posts: 4,640

Re: Crosstables with arrays / several conditions

Something like this?

data have;
input gdrg (icd_n1-icd_n5) ($) fab $;
datalines;
1 test1 test10 test test70 test50 fab51
1 test15 test10 test test70 test50 fab4
0 test10 test10 test test50 test15 fab32
1 test1 test10 test15 test70 test50 fab4
1 test1 test15 test test70 test50 fab10
;

data haveList(keep=t fab);
set have;
array icd_n{100};
if gdrg;
do i = 1 to dim(icd_n);
     t = icd_n{i};
     if not missing(t) then output;
     end;
run;

proc sql;
create table wantList as
select t, fab, count(*) as n
from haveList
group by t, fab
order by t;
quit;

proc transpose data=wantList out=want(drop=_name_);
by t;
var n;
id fab;
run;

PG

PG

View solution in original post


All Replies
Respected Advisor
Posts: 4,640

Re: Crosstables with arrays / several conditions

Please give us a small example of input and expected output data. - PG

PG
Occasional Contributor
Posts: 10

Re: Crosstables with arrays / several conditions

Input:

Dummy variable gdrg

set of alphanumeric variables icd_n* where star is a number from 1 to 100. Variables have values "test","test1",test2",...., "test100"

character variable fab with values "fab1", "fab2",...."fab100"

Output:

A table counting all observations, excluding gdrg =0;

Columns: fab1 to fab100

Rows: test1, test10, test50, test70

The thing is, test1,10,... can occur in all icd_n* variables. If the icd_n* value, which is selected for the rows, occurs together with another one of the selected row values within one observation but in different icd_n* variables, they should be accounted for separately. Hope that this explanation is more clear.

Solution
‎04-01-2013 10:26 PM
Respected Advisor
Posts: 4,640

Re: Crosstables with arrays / several conditions

Something like this?

data have;
input gdrg (icd_n1-icd_n5) ($) fab $;
datalines;
1 test1 test10 test test70 test50 fab51
1 test15 test10 test test70 test50 fab4
0 test10 test10 test test50 test15 fab32
1 test1 test10 test15 test70 test50 fab4
1 test1 test15 test test70 test50 fab10
;

data haveList(keep=t fab);
set have;
array icd_n{100};
if gdrg;
do i = 1 to dim(icd_n);
     t = icd_n{i};
     if not missing(t) then output;
     end;
run;

proc sql;
create table wantList as
select t, fab, count(*) as n
from haveList
group by t, fab
order by t;
quit;

proc transpose data=wantList out=want(drop=_name_);
by t;
var n;
id fab;
run;

PG

PG
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 239 views
  • 1 like
  • 2 in conversation