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
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
Please give us a small example of input and expected output data. - PG
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.
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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.