Help using Base SAS procedures

Put in column

Accepted Solution Solved
Reply
Regular Contributor
Regular Contributor
Posts: 238
Accepted Solution

Put in column

I want to take a table that has the following: there are 86k rows that vary

memberID     yes         no

111                0            1

222                1            0

I want my output to be:

who              admission            count

national          yes                       0

national          no                         1

national         yes                        1

national          no                         0

The code I have is:

data chi (drop = yes no);

set final;

array _col(2) yes no;

do _n_=1to2;

who = vname (national);

admission = vname(_col(_n_));

count = _col(_n_);

output;

end;

run;

The table looks like this:

who                  national                admission          count

national                                            yes                  0

national                                             no                   1

national                                            yes                  1

national                                             no                   0

I do not want the national colunmn. Just the who column with national in it and then admission with yes and no and then the count


Accepted Solutions
Solution
‎03-14-2012 04:43 PM
Regular Contributor
Posts: 233

Put in column

Code:

DATA TEMP;
INPUT memberID     yes         no;
CARDS;
111                0            1
222                1            0
;
RUN;

data chi (drop = yes no);
set TEMP;
array _col(2) yes no;
do _n_= 1,2;
who = vname (national);
admission = vname(_col(_n_));
count = _col(_n_);
output;
end;
DROP NATIONAL;
run;

PROC PRINT;
RUN;

Output:

                         member
                        Obs      ID        who       admission    count

                         1       111     national       yes         0
                         2       111     national       no          1
                         3       222     national       yes         1
                         4       222     national       no          0


View solution in original post


All Replies
Respected Advisor
Posts: 4,919

Put in column

What is the relationship between WHO and memberID?

PG

PG
Solution
‎03-14-2012 04:43 PM
Regular Contributor
Posts: 233

Put in column

Code:

DATA TEMP;
INPUT memberID     yes         no;
CARDS;
111                0            1
222                1            0
;
RUN;

data chi (drop = yes no);
set TEMP;
array _col(2) yes no;
do _n_= 1,2;
who = vname (national);
admission = vname(_col(_n_));
count = _col(_n_);
output;
end;
DROP NATIONAL;
run;

PROC PRINT;
RUN;

Output:

                         member
                        Obs      ID        who       admission    count

                         1       111     national       yes         0
                         2       111     national       no          1
                         3       222     national       yes         1
                         4       222     national       no          0


🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 144 views
  • 0 likes
  • 3 in conversation