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
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.
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.