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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Hima
Obsidian | Level 7

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

2 REPLIES 2
PGStats
Opal | Level 21

What is the relationship between WHO and memberID?

PG

PG
Hima
Obsidian | Level 7

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


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 594 views
  • 0 likes
  • 3 in conversation