I have a dataset that looks like this:
subjid week seqday score
1 1 1 4
1 1 2 5
1 1 3 0
1 1 4 1
1 1 5 .
1 1 6 3
1 1 7 2
1 8 50 1
1 8 51 0
1 8 52 0
1 12 78 1
1 12 79 2
1 16 106 3
1 16 107 .
I basically want to keep data of every 2nd day of the week. So that corresponds to numbers 2, 51, 79, 107 in variable seqday so it looks like this:
subjid week seqday score
1 1 2 5
1 8 51 0
1 12 79 2
1 16 107 .
And then I would like to transpose the data so that it reads
subjid week1score week8score week12score week16score
1 5 0 2 .
I'm thinking the code should be (but didnt work):
data new;
set old;
if seqday = 2 or 51 or 79 or 107;
run;
proc transpose data=new out=newA
by subjid;
var score;
run;
You were close but, when coding in SAS, you have to use the SAS language. e.g.:
data new;
set old;
if seqday in (2,51,79,107);
run;
proc transpose data=new out=newA (drop=_:) prefix=week suffix=score;
by subjid;
var score;
id week;
run;
Art, CEO, AnalystFinder.com
You were close but, when coding in SAS, you have to use the SAS language. e.g.:
data new;
set old;
if seqday in (2,51,79,107);
run;
proc transpose data=new out=newA (drop=_:) prefix=week suffix=score;
by subjid;
var score;
id week;
run;
Art, CEO, AnalystFinder.com
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.