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
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
What is the relationship between WHO and memberID?
PG
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
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.
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.