BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dennisl
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

3 REPLIES 3
PGStats
Opal | Level 21

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

PG
dennisl
Calcite | Level 5

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.

PGStats
Opal | Level 21

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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