Hi All
Apologies for the semi-descriptive title...if any one can suggest a better one and I can change it then please let me know!
OK, to the problem, sounds an easy one but can;t think of an easy solution.
I have a dataset of subject and timepoint info.
001 Screening
001 Visit 1
001 Visit 2
002 Screening
002 Visit 1
002 Visit 3
I need to create a new dataset where each subject in the output dataset has 4 records per timepoint? They have 4 tests done at each timepoint
Test1
Test2
Test3
Test4
So final dataset should look something like
001 Screening Test1
001 Screening Test2
001 Screening Test3
001 Screening Test4
001 Visit 1 Test1
001 Visit 1 Test2
001 Visit 1 Test3
001 Visit 1 Test4
....
....
....
Thanks!
Steve
The output data will be exported to excel and then filled in by hand
data have;
input id $ visit :$9.;
cards;
001 Screening
001 Visit1
001 Visit2
002 Screening
002 Visit1
002 Visit3
;
data want;
set have;
do test="test1", "test2", "test3", "test4";
output;
end;
proc print;
run;
data want (drop=i);
set have;
do i=1 to 4;
newvar='test'||put(i,1.);
output;
end;
run;
Thanks Art
sorry the test1-test4 was an example
test could be like:
RBC
WBC
Urine
Platelets
Not in a sequential number as such
Apologies for the confusion
Steve
Then how about:
data want (drop=i _:);
set have;
array _new(4) $10. ('RBC' 'WBC' 'Urine' 'Platelets');
do i=1 to 4;
newvar=_new(i);
output;
end;
run;
Thanks Linlin
Can you possibly expalin the logic here or tell me where in the SAS documentation I can read up on this. I've not seen this do loop construction/use before. Interesting.
Regards
Steve
Understood. Linlin's suggested code was an example of one of the forms of an interative do loop. It is documented at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201276.htm
However, in your case, you will also need to include a length statement or else the length will be determined by the first value in the list. e.g.,
data want;
set have;
length test $10;
do test='RBC','WBC','Urine','Platelets';
output;
end;
run;
Thanks Art
Gonna go for Linlins option as a novel insight for me...and I don;t like arrays! :smileyshocked:
data have;
input id $ visit :$9.;
cards;
001 Screening
001 Visit1
001 Visit2
002 Screening
002 Visit1
002 Visit3
;
data want;
set have;
do test="test1", "test2", "test3", "test4";
output;
end;
proc print;
run;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.